




已阅读5页,还剩9页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
四 川 大 学 计 算 机 学 院、软 件 学 院实 验 报 告 学号:_1043111034 姓名:陈枝 专业:软件工程班级:3 第 14 周 课程名称 信息安全产品开发实践实验课时5实验项目多路IO复用并发服务器模型网络嗅探器实验时间12.07实验目的 使用Libpcap库捕获局域网中的IP包实验环境 X86;WindowsXP;VMware Workstation 5.0.0; SSHSecureShellClient-3.2.9实验内容(算法、程序、步骤和方法) 根据课程内容: 嗅探器概述 Libpcap简介、安装与程序编译 利用Libpcap进行网络嗅探的工作流程 Libpcap 主要函数简介使用Libpcap库捕获局域网中的IP包,要求:1. 打印数据包的源与目的物理地址;2. 打印源与目的地址;3. 打印出上层协议类型;4. 如果上层协议为TCP或UDP协议,打印目的与源端口信息;5. 如果上层协议为TCP或UDP协议,将数据以16进制与ASCII的两种方式同时打印出来,不可打印字符以.代替; 00000 47 45 54 20 2f 20 48 54 54 50 2f 31 2e 31 0d 0a GET / HTTP/1.1.解决思路:1:在main函数中捕获网卡设备设置过滤策略循环抓包2:在packet_process函数中解析抓包内的数据,分层逐步从链路层到传输层,一层一层解析3:在print_data函数与print函数的结合下按照16进制与ascii两种方式进行对齐打印。(接上)实验内容(算法、程序、步骤和方法)根据以下内容写出以下程序:#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#include#define DEFAULT_SNAPLEN 1518/打印16进制与asciivoid print(u_char*payload,int len,int offset,int maxlen)printf(%.5d ,offset);int max=maxlen;int i;for(i=0;i0)printf(%.2x ,payloadmax-(len-i);elseprintf( );printf( );for(i=0;i16;i+)if(isprint(payloadmax-(len-i)printf(%c,payloadmax-(len-i);elseprintf(.);/打印数据包void print_data(u_char *payload,int len)int line_width=16;int len_rem=len;int maxlen=len;int offset=0;while(1)if(len_remline_width)if(len_rem=0)break;else print(payload,len_rem,offset,maxlen);offset=offset+len_rem;printf(n);break;elseprint(payload,len_rem,offset,maxlen);offset=offset+16;printf(n);len_rem=len_rem-line_width;/打印mac地址函数void print_mac(u_char* macadd)int i;for(i=0;i5;i+)printf(%.2x:,macaddi);printf(%.2x,macaddi);/打印ip地址void print_ip(u_char* ipadd)int i;for(i=0;its).tv_sec); /show the time;printf(Packet number:%dn,+packet_num);/show the packet num;printf(Packet length:%dn,h-len);/ show the packet len;int i;eth=(struct ether_header *)p;printf(Source Mac Address: );print_mac(eth-ether_shost);printf(n);printf(Destination Mac Address:);print_mac(eth-ether_dhost);printf(n);/判断网路层协议unsigned int typeno;typeno=ntohs(eth-ether_type);switch(typeno)case ETHERTYPE_IP:printf(IPV4n);break;case ETHERTYPE_PUP:printf(PUPn);break;case ETHERTYPE_ARP:printf(ARPn);break;default:printf(unknown network layer typesn);if(typeno=ETHERTYPE_IP)iph=(struct ip*)(p+sizeof(struct ether_header);printf(Source Ip Address:);print_ip(u_char*)&(iph-ip_src);printf(n);printf(Destination Ip address:);print_ip(u_char *)&(iph-ip_dst);printf(n);printf(Transport layer protocal:n);if(iph-ip_p=1)/判断传输层协议printf(ICMPn);else if(iph-ip_p=2)printf(IGMPn);else if(iph-ip_p=6)printf(TCPn);tcph=(struct tcphdr*)(p+sizeof(struct ether_header)+sizeof(struct ip);printf(destport :%dn,ntohs(tcph-dest);printf(sourport:%dn,ntohs(tcph-source);printf(Payload:n);print_data(p,h-len);else if(iph-ip_p=17)printf(UDPn);printf(application layer protocol:n);udph=(struct udphdr*)(p+sizeof(struct ether_header)+sizeof(struct ip);printf(dest port:%dn,ntohs(udph-dest);printf(source port%dn:,ntohs(udph-source);printf(Payload:n);print_data(p,h-len);else printf(unknown protocoln);int main(int argc,char* argv)char ebufPCAP_ERRBUF_SIZE;pcap_t *pd;struct bpf_program fcode;bpf_u_int32 netaddr=0,mask=0;int i=0;if(argc =1)printf(usage:%s,argv0);exit(1);/open the port and set if(pd=pcap_open_live(argv1,DEFAULT_SNAPLEN,1,1000,ebuf)=NULL)(void)fprintf(stderr,%s,ebuf);exit(1);/find the netaddr and maskif(i=pcap_lookupnet(argv1, &netaddr, &mask, ebuf)=-1)(void)fprintf(stderr,%s,ebuf);exit(1);/set the filterpcap_compile(pd,&fcode,ip,1,mask);pcap_setfilter(pd,&fcode);/get the packetif(pcap_loop(pd,-1,packet_process,NULL)0)(void)fprintf(stderr,pcap_loop:%sn,pca
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年宿州市中医医院招聘卫生专业技术人员36人模拟试卷及答案详解(名师系列)
- 2025辽宁兴城市人民医院、中医医院招聘急需紧缺人才37人考前自测高频考点模拟试题及答案详解1套
- 2025内蒙古镶黄旗蒙金矿业开发有限公司招聘25人模拟试卷参考答案详解
- 2024年云南昭通云富街道招聘乡村公益性岗位工作人员考试真题
- 2025甘肃兰州新区市政投资管理集团有限公司招聘32人考前自测高频考点模拟试题及参考答案详解1套
- 2025年黑河市北安市公开招聘社区工作者17人模拟试卷及参考答案详解1套
- 2025年上半年江苏徐州市九州职业技术学院招聘考前自测高频考点模拟试题及答案详解(各地真题)
- 2025年公开选聘珙县县属国有企业领导人员拟聘用人员的考前自测高频考点模拟试题及答案详解(网校专用)
- 2025安徽宿州学院专职辅导员招聘12人模拟试卷参考答案详解
- 2025广东深圳市九洲电器有限公司招聘产品经理模拟试卷及参考答案详解1套
- 头颈部鳞癌治疗现状及免疫治疗进展
- 微信小程序开发-微信小程序云开发
- 书写板卫生安全要求
- 中成药合理使用
- GB/T 30193-2013工程机械轮胎耐久性试验方法
- GB/T 23260-2009带自粘层的防水卷材
- GA 1551.6-2021石油石化系统治安反恐防范要求第6部分:石油天然气管道企业
- GA 1732-2020警用无人驾驶航空器外观制式涂装规范
- CB/T 749-1997固定钢质百叶窗
- 一年级《劳动实践指导手册》《学习用品我整理》课件
- 水果拼盘拼盘课件
评论
0/150
提交评论