




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
上机1:基于WinPcap的网络嗅探器设计1、目的与要求掌握基于WinPcap的网络编程模式。理解并能应用WinPcap设计并实现网络数据包的捕获与解析。2、设备与上机环境l 连网PC机(至少一台)。l 计算机硬件要求:Intel Pentium5 处理器、256MB以上内存,Ethernet网卡,网线若干。l 计算机软件要求:MS Windows 9x/2000/XP操作系统,TCP/IP协议,WinPcap430,Visual c+6.0/.net系统。3、上机内容与步骤:在程序设计之前,请参照提供的软件安装WinPcap。之后,按照如下步骤操作:步骤1:在VC+ 6.0下创建一个DOS命令行程序,工程名:自己的学号-PacketDump步骤2:打开main()函数,在主程序中增加如下头文件和常量定义:#include #define LINE_LEN 16pcap_if_t *alldevs, *d;pcap_t *fp;u_int inum, i=0;char errbufPCAP_ERRBUF_SIZE;int res;struct pcap_pkthdr *header;const u_char *pkt_data;printf(pktdump_ex: prints the packets of the network using WinPcap.n);printf( Usage: pktdump_ex -s sourcenn Examples:n pktdump_ex -s file.acpn pktdump_ex -s DeviceNPF_C8736017-F3C3-4373-94AC-9A34B7DAD998nn);if(argc next)printf(%d. %sn , +i, d-name);if (d-description)printf( (%s)n, d-description);elseprintf( (No description available)n);if (i=0)printf(nNo interfaces found! Make sure WinPcap is installed.n);return -1;printf(Enter the interface number (1-%d):,i);scanf(%d, &inum);if (inum i)printf(nInterface number out of range.n);/* Free the device list */pcap_freealldevs(alldevs);return -1;/* Jump to the selected adapter */for (d=alldevs, i=0; inext, i+);/* Open the adapter */if (fp = pcap_open_live(d-name,/ name of the device65536,/ portion of the packet to capture. / 65536 grants that the whole packet will be captured on all the MACs.1,/ promiscuous mode (nonzero means promiscuous)1000,/ read timeouterrbuf/ error buffer) = NULL)fprintf(stderr,nError opening adaptern);return -1;else /* Do not check for the switch type (-s) */if (fp = pcap_open_live(argv2,/ name of the device65536,/ portion of the packet to capture. / 65536 grants that the whole packet will be captured on all the MACs.1,/ promiscuous mode (nonzero means promiscuous)1000,/ read timeouterrbuf/ error buffer) = NULL)fprintf(stderr,nError opening adaptern);return -1;/* Read the packets */while(res = pcap_next_ex( fp, &header, &pkt_data) = 0)if(res = 0)/* Timeout elapsed */continue;/* print pkt timestamp and pkt len */printf(%ld:%ld (%ld)n, header-ts.tv_sec, header-ts.tv_usec, header-len);/* Print the packet */for (i=1; (i caplen + 1 ) ; i+)printf(%.2x , pkt_datai-1);if ( (i % LINE_LEN) = 0) printf(n);printf(nn);if(res = -1)printf(Error reading the packets: %sn, pcap_geterr(fp);return -1;pcap_close(fp);return 0;步骤3:为编译器指定包含文件和库文件搜索目录。假定WinPcap开发包WpdPack_4_0_2.zip被解压缩到C盘,如下图:为编译器指定包含文件和库文件搜索目录的方法如下:在VC+6.0下,打开Tools菜单,选择Options,然后选择Directories选项卡,指定WinPcap包含文件和库文件目录,如下图所示。步骤4:指定链接的库文件。方法:打开Project菜单,选择Settings,选择Link选项卡,然后把wpcap.lib
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年浙江省杭州市事业单位招聘考试综合类无领导小组讨论面试真题模拟试卷
- 2025年河北事业单位招聘考试综合类公共基础知识真题模拟试卷
- 核电站保安考试题及答案
- 2025国考朝阳市法语翻译岗位申论模拟题及答案
- 2025国考晋城市能源管理岗位行测高频考点及答案
- 2025国考包头市英语翻译岗位申论高频考点及答案
- 2025国考鞍山市预算管理岗位申论模拟题及答案
- 2025国考安徽俄语专业科目高频考点及答案
- 2025国考安徽财监申论大作文预测卷及答案
- 2025国考云南统计局行测常识判断易错点
- 项目管理课件培训
- 急性牙髓炎个案护理
- 嘉宾邀请活动方案
- 2025至2030中国游戏陪玩行业市场发展分析及发展前景与投资报告
- 食管恶性肿瘤的健康教育讲课件
- 临床重点专科管理制度
- 交通事故和解协议范本
- 公司航测无人机管理制度
- 模具超寿命管理制度
- 违法建筑处置法律解读培训
- TSG D7004-2010 压力管道定期检验规则 -公用管道
评论
0/150
提交评论