ImageVerifierCode 换一换
格式:DOCX , 页数:15 ,大小:19.77KB ,
资源ID:24576250      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/24576250.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(计算机网络编程课程设计.docx)为本站会员(b****2)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

计算机网络编程课程设计.docx

1、计算机网络编程课程设计课题一:基于TCP的Socket通讯编程1、课程设计目的:1.能够深刻了解socket编程思想;2.从实现层面理解TCP和UDP链接的不同。2、课程设计环境:1.windows XP或 win7 系统;2.配置有java虚拟机的环境变量;3.编写java程序的软件Eclipse。3、课程设计原理: Windows Sockets规范本意在于提供给应用程序开发者一套简单的API,并让各家网络软件供应商共同遵守。此外,在一个特定版本Windows的基础上,Windows Sockets也定义了一个二进制接口(ABI),以此来保证应用Windows Sockets API的应用

2、程序能够在任何网络软件供应商的符合Windows Sockets协议的实现上工作。因此这份规范定义了应用程序开发者能够使用,并且网络软件供应商能够实现的一套库函数调用和相关语义。 遵守这套Windows Sockets规范的网络软件,我们称之为Windows Sockets兼容的,而Windows Sockets兼容实现的提供者,我们称之为Windows Sockets提供者。一个网络软件供应商必须百分之百地实现Windows Sockets规范才能做到现Windows Sockets兼容。4、课程设计内容:(1)网络程序初始化,服务器和客户端WinSock API均要求在调用其他WinSoc

3、k函数以前先调用WSAStartUp函数初始化。 (2)创建套接字Socket()。 (3)配置并启动套接字。 (4)通过Socket发送和接收数据。 (5)程序结束时必须关闭Socket,使用与WSAStartUp()相对应的函数WSACleanUp(),释放所分配的内部缓冲区和其他资源。代码:EchoThreadServer:import .*;public class EchoThreadServer public static void main(String args) throws Exception / TODO Auto-generated method stub Server

4、Socket server = null; Socket client = null; InetAddress remAdd = null; server = new ServerSocket(12345); boolean f = true; while (f) ); client = server.accept(); new Thread(new EchoThread(client).start(); server.close(); EchoThread:import java.io.*;public class EchoThread implements Runnable private

5、 Socket client = null; public EchoThread(Socket client) this.client = client; public void run() BufferedReader buf = null; PrintStream out = null; BufferedReader input = null; try out = new PrintStream(client.getOutputStream(); buf = new BufferedReader(new InputStreamReader(client.getInputStream();

6、input = new BufferedReader(new InputStreamReader(System.in); boolean flag = true ; while(flag) String str = buf.readLine(); if (str = null | .equals(str) flag = false; else if(goodbye.equals(str) flag = false; else out.println(Echo: + str); client.close(); catch (Exception e) / TODO: handle exceptio

7、n EchoClient:public class EchoClient public static void main(String args) throws Exception Socket client = null; client = new Socket(localhost,12345); BufferedReader buf = null; PrintStream out = null; BufferedReader input = null; input = new BufferedReader(new InputStreamReader(System.in); buf = ne

8、w BufferedReader(new InputStreamReader(client.getInputStream(); out = new PrintStream(client.getOutputStream(); boolean flag = true; while(flag) String str = input.readLine(); out.println(str); if (goodbye.equals(str) flag = false; else String echo = buf.readLine(); buf.close(); client.close(); 5、课程

9、设计结果截图:服务器端截图:客户端截图:6、课程设计总结:课题二:端口扫描1、课程设计目的:1.加深对课堂讲授知识的理解;2.熟练的掌握基本的网络编程技术和方法;3.建立网络编程整体概念;4.培养具有研究、设计、编制和调试网络程序的能力。2、课程设计环境:1.windows XP或 win7 系统;2.配置有java虚拟机的环境变量;3.编写java程序的软件Eclipse。3、课程设计原理:1端口扫描器功能简介:服务器上所开放的端口就是潜在的通信通道,也就是一个入 侵通道。对目标计算机进行端口扫描,能得到许多有用的信息,进行端口扫描的方法很多,可以是手工进行扫描、也可以用端口扫描软件进行。扫

10、描器通过选用远程TCP/IP不同的端口的服务,并记录目标给予的回答,通过这种方法可以搜集到很多关于目标主机的各种有用的信息,例如远程系统是否支持匿名登陆、是否存在可写的 FTP 目录、是否开放 TELNET 服务和 HTTPD 服务等。 2实验所用的端口扫描技术:端口扫描技术有 TCP connect()扫描、 TCP SYN 扫描、TCP FIN 扫描、IP段扫描等等。本次实验所用的技术是TCP connect()扫描,这是最基本的TCP扫描,操作系统提供的 connect()系统调用可以用来与每一个感兴趣的目标计算机的端口进行连接。如果端口处于侦听状态,那么connect()就能成功。否则

11、,这个端口是不能用的,即 没有提供服务。这个技术的一个最大的优点是,你不需要任何权限。系统中的任何用户都有权利使用这个调用。4、课程设计内容:编写一个端口扫描程序,能够显示某个IP或某段IP的计算机的某一个或某些端口是否正在工作。基本工作过程如下:(1)设定好一定的端口扫描范围;(2)设定每个端口扫描的次数,因为有可能有的端口一次扫描可能不通; (3)创建 socket,通过socket的connect方法来连接远程IP地址以及对应的端口; (4)如果返回false,表示端口没有开放,否则端口开放。实现代码:public class SocketView public static void

12、main(String args) JFrame frame = new JFrame(主机端口扫描程序); frame.setLayout(new BorderLayout(3,3); JPanel pan1 = new JPanel(); JPanel pan2 = new JPanel(); JPanel pan3 = new JPanel(); pan1.setLayout(new GridLayout(2,2,5,5); pan2.setLayout(new BorderLayout(3,3); pan3.setLayout(new GridLayout(1,2,5,5); fram

13、e.setSize(400, 450); /定义各个组件 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);

14、 JButton jb2 = new JButton(UDP Scan); JScrollPane jp = new JScrollPane(ja); pan1.add(lb1); pan1.add(lb2); pan1.add(jf1); pan1.add(jf2); pan2.add(lb3,BorderLayout.NORTH); pan2.add(jp,BorderLayout.CENTER); pan3.add(jb1); pan3.add(jb2); frame.add(pan1,BorderLayout.NORTH); frame.add(pan2,BorderLayout.CE

15、NTER); frame.add(pan3,BorderLayout.SOUTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); jb1.addActionListener(new SocketPort(); class SocketPort implements ActionListener private String ip = jf1.getText(); private String hostname = new String(); public void actionPer

16、formed(ActionEvent e) try InetAddress address = InetAddress.getByName(ip); hostname = address.getHostName(); ja.setText(hostname); catch (Exception exception) ja.setText(Could not find + ip); try PrintWriter fout = new PrintWriter( new FileWriter(PortInf.txt); fout.println(Information Of The Port On

17、 the + hostname +computer ); fout.println(); ja.setText(Information Of The Port On the + hostname +computer); for(int nport = 25;nport 27;+nport) try Socket s = new Socket(hostname,nport); fout.println(The port + nport + is open!); fout.println(Connected to + s.getInetAddress() + on port + s.getPort

18、() + from port + s.getLocalPort() + of + s.getLocalAddress(); ja.setText(The port + nport + is open!); ja.setText(Connected to + s.getInetAddress() + on port + s.getPort() + from port + s.getLocalPort() + of + s.getLocalAddress(); catch (Exception exception) / TODO: handle exception fout.println(The

19、 port + nport + is closed!); ja.setText(The port + nport + is closed!); fout.close(); catch (Exception exception) exception.printStackTrace(); 5、课程设计结果截图:6、课程设计总结课题三:捕获分析IP数据包1、课程设计目的:1.掌握IP数据报的格式;2.理解IP协议的工作原理及工作过程;3.学会网络编程的方法和技巧。2、课程设计环境:1.windows XP或 win7 系统;2.以太网,可以访问外部网页;3.VC程序编辑器。3、课程设计原理: IP

20、数据包的格式说明IP数据包格式包含了标头固定部分,标头可变部分和数据区三部分。IP数据报标头部分固定为20个字节,其中包含了12个参数域,各参数域隐含着网间协议的传输机制。IP具体的标头格式如图所示。4、课程设计内容:本设计的目标是捕获网络中的IP数据包,解析数据包的内容,将结果显示在标准输出上,并同时写入日志文件。程序的具体要求如下:(1)捕获网络中的IP数据包,解析数据包的内容,显示结果,并将结果写入日志文件。(2)显示的内容包括:捕获的IP包的版本、头长度、服务类型、数据包总长度、数据包标识、分段标志、分段偏移值、生存时间、上层协议类型、头校验和、源IP地址和目的IP地址等内容。(3)设

21、置停止标志,当程序接收到停止命令时即停止。代码:#include #pragma comment( lib, Ws2_32.lib );struct ether_header u_int8_t ether_dhost6; u_int8_t ether_shost6; 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_

22、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_pac

23、ket_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); head

24、er_length=ip_protocol-ip_header_length*4; tos=ip_protocol-ip_tos; offset=ntohs(ip_protocol-ip_off); printf(-ip协议包-n); printf(版本 :%dn,ip_protocol-ip_version); printf(首部长度:%dn,header_length); printf(服务类型 :%dn,tos); printf(总长度 :%dn,ntohs(ip_protocol-ip_length); printf(标识 :%dn,ntohs(ip_protocol-ip_id);

25、printf(偏移:%dn,(offset&0x1fff)*8); printf(生存时间:%dn,ip_protocol-ip_ttl); printf(协议:%dn,ip_protocol-ip_protocol); switch(ip_protocol-ip_protocol) case 6: printf(该数据包协议类型是 Tcpn); break; case 17: printf(该数据包协议类型是 Udpn); break; case 1: printf(该数据包协议类型是 Icmpn); break; default: break; printf(校验和:%dn,checksu

26、m); printf(源地址 :%sn,inet_ntoa(ip_protocol-ip_source_address); printf(目的地址 :%sn,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 *et

27、hernet_protocol; u_char *mac_string; static int packet_number=1;printf(*n); printf( the %d packet is captured n,packet_number); printf(-以太网帧-n); ethernet_protocol=(struct ether_header *)packet_content; printf(以太网帧类型:); ethernet_type=ntohs(ethernet_protocol-ether_type); printf(%04xn,ethernet_type); s

28、witch(ethernet_type) case 0x0800: printf(网络层协议是 ip 协议n); break; case 0x0806: printf(网络层协议是 arp 协议n); break; case 0x8035: printf(网络层协议是 rarp 协议n); break; default: break; printf(MAC源地址:); mac_string=ethernet_protocol-ether_shost;printf(%02x:%02x:%02x:%02x:%02x:%02xn,*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:

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1