亚洲一区爱区精品无码_无码熟妇人妻AV_日本免费一区二区三区最新_国产AV寂寞骚妇

計(jì)算機(jī)網(wǎng)絡(luò)編程課程設(shè)計(jì)(網(wǎng)絡(luò)程序設(shè)計(jì)課程)

時(shí)間:2022-06-05 08:06:08 綜合范文

  下面是范文網(wǎng)小編收集的計(jì)算機(jī)網(wǎng)絡(luò)編程課程設(shè)計(jì)(網(wǎng)絡(luò)程序設(shè)計(jì)課程),歡迎參閱。

計(jì)算機(jī)網(wǎng)絡(luò)編程課程設(shè)計(jì)(網(wǎng)絡(luò)程序設(shè)計(jì)課程)

  課題一:基于TCP的Socket通訊編程 一、 課程設(shè)計(jì)目的:

  1. 能夠深刻了解socket編程思想;

  2. 從實(shí)現(xiàn)層面理解TCP和UDP鏈接的不同。

  二、 課程設(shè)計(jì)環(huán)境:

  1. windows XP或 win7 系統(tǒng);

  2. 配置有java虛擬機(jī)的環(huán)境變量;

  3. 編寫java程序的軟件Eclipse。

  三、 課程設(shè)計(jì)原理:

  Windows Sockets規(guī)范本意在于提供給應(yīng)用程序開發(fā)者一套簡單的API,并讓各家網(wǎng)絡(luò)軟件供應(yīng)商共同遵守。此外,在一個(gè)特定版本W(wǎng)indows的基礎(chǔ)上,Windows Sockets也定義了一個(gè)二進(jìn)制接口(ABI),以此來保證應(yīng)用Windows Sockets API的應(yīng)用程序能夠在任何網(wǎng)絡(luò)軟件供應(yīng)商的符合Windows Sockets協(xié)議的實(shí)現(xiàn)上工作。因此這份規(guī)范定義了應(yīng)用程序開發(fā)者能夠使用,并且網(wǎng)絡(luò)軟件供應(yīng)商能夠?qū)崿F(xiàn)的一套庫函數(shù)調(diào)用和相關(guān)語義。

  遵守這套Windows Sockets規(guī)范的網(wǎng)絡(luò)軟件,我們稱之為Windows Sockets兼容的,而Windows Sockets兼容實(shí)現(xiàn)的提供者,我們稱之為Windows Sockets提供者。一個(gè)網(wǎng)絡(luò)軟件供應(yīng)商必須百分之百地實(shí)現(xiàn)Windows Sockets規(guī)范才能做到現(xiàn)Windows Sockets兼容。

  四、 課程設(shè)計(jì)內(nèi)容:

  (1)

  網(wǎng)絡(luò)程序初始化,服務(wù)器和客戶端WinSock API均要求在調(diào)用其他WinSock函數(shù)以前先調(diào)用WSAStartUp函數(shù)初始化。

 ?。?)創(chuàng)建套接字Socket()。

 ?。?)配置并啟動(dòng)套接字。

 ?。?)通過Socket發(fā)送和接收數(shù)據(jù)。

 ?。?)程序結(jié)束時(shí)必須關(guān)閉Socket,使用與WSAStartUp()相對(duì)應(yīng)的函數(shù)WSACleanUp(),釋放所分配的內(nèi)部緩沖區(qū)和其他資源。

  代碼:

  EchoThreadServer: import *; public class EchoThreadServer { public static void main(String[] args) throws Exception{ // TODO Auto-generated method stub ServerSocket server = null; Socket client = null; InetAddress remAdd = null; server = new ServerSocket(); boolean f = true; while (f) { (“連接正在建立,請(qǐng)等待……“); client = (); (“客戶端的IP地址和端口號(hào)是:“ + ()); new Thread(new EchoThread(client)).start(); } (); } } EchoThread: import *; import ; public class EchoThread implements Runnable{ private Socket client = null; public EchoThread(Socket client) { = client; } public void run() { BufferedReader buf = null; PrintStream out = null; BufferedReader input = null; try { out = new PrintStream(()); buf = new BufferedReader(new InputStreamReader(())); input = new BufferedReader(new InputStreamReader()); boolean flag = true ; while(flag) { String str = (); (“Client:“ + str); if (str == null || ““.equals(str)) { flag = false; } else if(“goodbye“.equals(str)) { flag = false; } else { (“Echo:“ + str); } } (); } catch (Exception e) { // TODO: handle exception } } } EchoClient: import ; import ; import ; import ; public class EchoClient { public static void main(String[] args) throws Exception{ Socket client = null; client = new Socket(“l(fā)ocalhost“,); BufferedReader buf = null; PrintStream out = null; BufferedReader input = null; input = new BufferedReader(new InputStreamReader()); buf = new BufferedReader(new InputStreamReader(())); out = new PrintStream(()); boolean flag = true; while(flag){ (“客戶端輸入信息:“); String str = (); (str); if (“goodbye“.equals(str)) { flag = false; } else { String echo = (); (echo); } } (); (); } } 五、 課程設(shè)計(jì)結(jié)果截圖:

  服務(wù)器端截圖:

  客戶端截圖:

  六、 課程設(shè)計(jì)總結(jié):

  課題二:端口掃描 一、 課程設(shè)計(jì)目的:

  1. 加深對(duì)課堂講授知識(shí)的理解;

  2. 熟練的掌握基本的網(wǎng)絡(luò)編程技術(shù)和方法;

  3. 建立網(wǎng)絡(luò)編程整體概念;

  4. 培養(yǎng)具有研究、設(shè)計(jì)、編制和調(diào)試網(wǎng)絡(luò)程序的能力。

  二、 課程設(shè)計(jì)環(huán)境:

   XP或 win7 系統(tǒng);

  2.配置有java虛擬機(jī)的環(huán)境變量;

  3.編寫java程序的軟件Eclipse。

  三、 課程設(shè)計(jì)原理: 1. 端口掃描器功能簡介:服務(wù)器上所開放的端口就是潛在的通信通道,也就是一個(gè)入 侵通道。對(duì)目標(biāo)計(jì)算機(jī)進(jìn)行端口掃描,能得到許多有用的信息,進(jìn)行端口掃描的方法很多,可以是手工進(jìn)行掃描、也可以用端口掃描軟件進(jìn)行。掃描器通過選用遠(yuǎn)程TCP/IP不同的端口的服務(wù),并記錄目標(biāo)給予的回答,通過這種方法可以搜集到很多關(guān)于目標(biāo)主機(jī)的各種有用的信息,例如遠(yuǎn)程系統(tǒng)是否支持匿名登陸、是否存在可寫的 FTP 目錄、是否開放 TELNET 服務(wù)和 HTTPD 服務(wù)等。

  2.實(shí)驗(yàn)所用的端口掃描技術(shù):端口掃描技術(shù)有 TCP connect()掃描、 TCP SYN 掃描、TCP FIN 掃描、IP段掃描等等。本次實(shí)驗(yàn)所用的技術(shù)是TCP connect()掃描,這是最基本的TCP掃描,操作系統(tǒng)提供的 connect()系統(tǒng)調(diào)用可以用來與每一個(gè)感興趣的目標(biāo)計(jì)算機(jī)的端口進(jìn)行連接。如果端口處于偵聽狀態(tài),那么connect()就能成功。否則,這個(gè)端口是不能用的,即 沒有提供服務(wù)。這個(gè)技術(shù)的一個(gè)最大的優(yōu)點(diǎn)是,你不需要任何權(quán)限。系統(tǒng)中的任何用戶都有權(quán)利使用這個(gè)調(diào)用。

  四、 課程設(shè)計(jì)內(nèi)容:

  編寫一個(gè)端口掃描程序,能夠顯示某個(gè)IP或某段IP的計(jì)算機(jī)的某一個(gè)或某些端口是否正在工作。基本工作過程如下:

  (1) 設(shè)定好一定的端口掃描范圍;

  (2) 設(shè)定每個(gè)端口掃描的次數(shù),因?yàn)橛锌赡苡械亩丝谝淮螔呙杩赡懿煌ǎ?/p>

  (3) 創(chuàng)建 socket,通過socket的connect方法來連接遠(yuǎn)程IP地址以及對(duì)應(yīng)的端口;

  (4)如果返回false,表示端口沒有開放,否則端口開放。

  實(shí)現(xiàn)代碼:

  package ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; public class SocketView { public static void main(String[] args) { JFrame frame = new JFrame(“主機(jī)端口掃描程序“); (new BorderLayout(3,3)); JPanel pan1 = new JPanel(); JPanel pan2 = new JPanel(); JPanel pan3 = new JPanel(); (new GridLayout(2,2,5,5)); (new BorderLayout(3,3)); (new GridLayout(1,2,5,5)); (400, 450); //定義各個(gè)組件 JLabel lb1 = new JLabel(“Host Address“); JLabel lb2 = new JLabel(“Port Number“); JLabel lb3 = new JLabel(“Port Status“); final JTextField jf1 = new JTextField(); final JTextField jf2 = new JTextField(); final JTextArea ja = new JTextArea(); JButton jb1 = new JButton(“TCP Scan“); JButton jb2 = new JButton(“UDP Scan“); JScrollPane jp = new JScrollPane(ja); (lb1); (lb2); (jf1); (jf2); (lb3,); (jp,); (jb1); (jb2); (pan1,); (pan2,); (pan3,); (_ON_CLOSE); (true); (new SocketPort()); class SocketPort implements ActionListener { private String ip = ();; private String hostname = new String(); public void actionPerformed(ActionEvent e) { try { InetAddress address = (ip); (address); hostname = (); (hostname); (hostname); } catch (Exception exception) { (“Could not find “+ ip); (“Could not find “+ ip); } try { PrintWriter fout = new PrintWriter( new FileWriter(““)); (“Information Of The Port On the “ + hostname +“computer “); (); (“Information Of The Port On the “ + hostname +“computer“); for(int nport = 25;nport < 27;++nport){ try { Socket s = new Socket(hostname,nport); (“The port “ + nport + “ is open!“); (“Connected to “+ () + “ on port “ + () + “ from port “+ () + “ of “ + ()); (“The port “ + nport + “ is open!“); (“Connected to “+ () + “ on port “ + () + “ from port “+ () + “ of “ + ()); } catch (Exception exception) { // TODO: handle exception (“The port “ + nport + “ is closed!“); (“The port “ + nport + “ is closed!“); } } (); } catch (Exception exception) { (); } } } } } 五、 課程設(shè)計(jì)結(jié)果截圖:

  六、 七、 課程設(shè)計(jì)總結(jié) 課題三:捕獲分析IP數(shù)據(jù)包 一、 課程設(shè)計(jì)目的:

  1. 掌握IP數(shù)據(jù)報(bào)的格式;

  2. 理解IP協(xié)議的工作原理及工作過程;

  3. 學(xué)會(huì)網(wǎng)絡(luò)編程的方法和技巧。

  二、 課程設(shè)計(jì)環(huán)境:

  1. windows XP或 win7 系統(tǒng);

  2. 以太網(wǎng),可以訪問外部網(wǎng)頁;

  3. VC程序編輯器。

  三、 課程設(shè)計(jì)原理:

  IP 數(shù)據(jù)包的格式說明IP數(shù)據(jù)包格式包含了標(biāo)頭固定部分,標(biāo)頭可變部分和數(shù)據(jù)區(qū)三部分。IP數(shù)據(jù)報(bào)標(biāo)頭部分固定為20個(gè)字節(jié),其中包含了12個(gè)參數(shù)域,各參數(shù)域隱含著網(wǎng)間協(xié)議的傳輸機(jī)制。IP具體的標(biāo)頭格式如圖所示。

  四、 課程設(shè)計(jì)內(nèi)容:

  本設(shè)計(jì)的目標(biāo)是捕獲網(wǎng)絡(luò)中的IP數(shù)據(jù)包,解析數(shù)據(jù)包的內(nèi)容,將結(jié)果顯示在標(biāo)準(zhǔn)輸出上,并同時(shí)寫入日志文件。

  程序的具體要求如下: (1)捕獲網(wǎng)絡(luò)中的IP數(shù)據(jù)包,解析數(shù)據(jù)包的內(nèi)容,顯示結(jié)果,并將結(jié)果寫入日志文件。

 ?。?)顯示的內(nèi)容包括:捕獲的IP包的版本、頭長度、服務(wù)類型、數(shù)據(jù)包總長度、數(shù)據(jù)包標(biāo)識(shí)、分段標(biāo)志、分段偏移值、生存時(shí)間、上層協(xié)議類型、頭校驗(yàn)和、源IP地址和目的IP地址等內(nèi)容。

 ?。?)設(shè)置停止標(biāo)志,當(dāng)程序接收到停止命令時(shí)即停止。

  代碼:

  #include <> #pragma comment( lib, “Ws2_“ ); struct ether_header { u_int8_t ether_dhost[6]; u_int8_t ether_shost[6]; u_int16_t ether_type; }; typedef u_int32_t in_addr_t; /*struct in_addr { in_addr_t s_addr; };*/ struct ip_header { #ifdef WORDS_BIGENDIAN u_int8_t ip_version:4; u_int8_t ip_header_length:4; #else u_int8_t ip_header_length:4; u_int8_t ip_version:4; #endif u_int8_t ip_tos; u_int16_t ip_length; u_int16_t ip_id; u_int16_t ip_off; u_int8_t ip_ttl; u_int8_t ip_protocol; u_int16_t ip_checksum; struct in_addr ip_source_address; struct in_addr ip_destination_address; }; void ip_protocol_packet_callback(u_char * argument,const struct pcap_pkthdr * packet_header, const u_char * packet_content) { struct ip_header * ip_protocol; u_int header_length; u_int offset; u_char tos; u_int16_t checksum; ip_protocol=(struct ip_header*)(packet_content+14); checksum=ntohs(ip_protocol->ip_checksum); header_length=ip_protocol->ip_header_length*4; tos=ip_protocol->ip_tos; offset=ntohs(ip_protocol->ip_off); printf(“-------------------------ip協(xié)議包--------------------\n“); printf(“版本 :%d\n“,ip_protocol->ip_version); printf(“首部長度:%d\n“,header_length); printf(“服務(wù)類型 :%d\n“,tos); printf(“總長度 :%d\n“,ntohs(ip_protocol->ip_length)); printf(“標(biāo)識(shí) :%d\n“,ntohs(ip_protocol->ip_id)); printf(“偏移:%d\n“,(offset&0x1fff)*8); printf(“生存時(shí)間:%d\n“,ip_protocol->ip_ttl); printf(“協(xié)議:%d\n“,ip_protocol->ip_protocol); switch(ip_protocol->ip_protocol) { case 6: printf(“該數(shù)據(jù)包協(xié)議類型是 Tcp\n“); break; case 17: printf(“該數(shù)據(jù)包協(xié)議類型是 Udp\n“); break; case 1: printf(“該數(shù)據(jù)包協(xié)議類型是 Icmp\n“); break; default: break; } printf(“校驗(yàn)和:%d\n“,checksum); printf(“源地址 :%s\n“,inet_ntoa(ip_protocol->ip_source_address)); printf(“目的地址 :%s\n“,inet_ntoa(ip_protocol->ip_destination_address)); } void ethernet_protocol_packet_callback(u_char *argument,const struct pcap_pkthdr * packet_header, const u_char * packet_content) { u_short ethernet_type; struct ether_header *ethernet_protocol; u_char *mac_string; static int packet_number=1; printf(“****************************************************************\n“); printf(“ the %d packet is captured \n“,packet_number); printf(“------------------------------以太網(wǎng)幀--------------------------\n“); ethernet_protocol=(struct ether_header *)packet_content; printf(“以太網(wǎng)幀類型:“); ethernet_type=ntohs(ethernet_protocol->ether_type); printf(“%04x\n“,ethernet_type); switch(ethernet_type) { case 0x0800: printf(“網(wǎng)絡(luò)層協(xié)議是 ip 協(xié)議\n“); break; case 0x0806: printf(“網(wǎng)絡(luò)層協(xié)議是 arp 協(xié)議\n“); break; case 0x8035: printf(“網(wǎng)絡(luò)層協(xié)議是 rarp 協(xié)議\n“); break; default: break; } printf(“MAC源地址:“); mac_string=ethernet_protocol->ether_shost; printf(“%02x:%02x:%02x:%02x:%02x:%02x\n“,*mac_string,*(mac_string+1),*(mac_string+2), *(mac_string+3),*(mac_string+4),*(mac_string+5)); printf(“MAC目的地址 :“); mac_string=ethernet_protocol->ether_dhost; printf(“%02x:%02x:%02x:%02x:%02x:%02x\n“,*mac_string,*(mac_string+1),*(mac_string+2), *(mac_string+3),*(mac_string+4),*(mac_string+5)); switch(ethernet_type) { case 0x0800 ip_protocol_packet_callback(argument,packet_header,packet_content); break; default: break; } printf(“********************************************************************\n“); packet_number++; } int main() { pcap_t *pcap_handle; char error_content[PCAP_ERRBUF_SIZE]; char *net_interface; struct bpf_program bpf_filter; char bpf_filter_string[]=“ip“; bpf_u_int32 net_mask; bpf_u_int32 net_ip; net_interface=pcap_lookupdev(error_content); pcap_lookupnet(net_interface,&net_ip,&net_mask,error_content); pcap_handle=pcap_open_live(net_interface,,1,0,error_content); pcap_compile(pcap_handle,&bpf_filter,bpf_filter_string,0,net_ip); pcap_setfilter(pcap_handle,&bpf_filter); if(pcap_datalink(pcap_handle)!=DLT_EN10MB) return 0; pcap_loop(pcap_handle,-1,ethernet_protocol_packet_callback,NULL); pcap_close(pcap_handle); } 五、 課程設(shè)計(jì)結(jié)果截圖:

  六、 課程設(shè)計(jì)總結(jié):

  七、 主要參考資料:

  [1]謝希仁.計(jì)算機(jī)網(wǎng)絡(luò)[M].第5版.北京:電子工業(yè)出版社,2008. [2]張基溫.Visual C++程序開發(fā)基礎(chǔ)[M].北京:高等教育出版社,2001. [3]f15瑞.Visual c++網(wǎng)絡(luò)通信程序開發(fā)指南[M].北京:機(jī)械工業(yè)出版社,2004.

  網(wǎng)絡(luò)工程課程設(shè)計(jì)

  網(wǎng)絡(luò)課程教學(xué)設(shè)計(jì)

  計(jì)算機(jī)網(wǎng)絡(luò)教學(xué)課件

  計(jì)算機(jī)網(wǎng)絡(luò)教學(xué)課件

  《C語言程序設(shè)計(jì)》網(wǎng)絡(luò)課程設(shè)計(jì)開題報(bào)告

計(jì)算機(jī)網(wǎng)絡(luò)編程課程設(shè)計(jì)(網(wǎng)絡(luò)程序設(shè)計(jì)課程)相關(guān)文章:


相關(guān)熱詞搜索:計(jì)算機(jī)網(wǎng)絡(luò)編程課程設(shè)計(jì)