Sniffer软件是NAI公司推出的一款一流的便携式网管和应用故障诊断分析软件,不管是在有线网络还是在无线网络中,它都能够给予网管管理人员实时的网络监视、数据包捕获以及故障诊断分析能力。对于在现场运行快速的网络和应用问题故障诊断,基于便携式软件的解决方案具备最高的性价比,却能够让用户获得强大的网管和应用故障诊断功能。[1]

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

int main(intargc,char**argv) {intsock,n;charbuffer[2048];unsignedchar*iphead,*ethhead;structifreqethreq;intno=0;//

设置原始套接字方式为接收所有的数据包if((sock=socket(PF_PACKET,SOCK_RAW,htons(ETH_P_IP)))<0){perror(“\n原始套接字建立失败\n”);exit(1);}//设置网卡工作方式为混杂模式,

SIOCGIFFLAGS请求表示需要获取接口标志strncpy(ethreq.ifr_name,”eth0”,IFNAMSIZ);//InterfaceNamesizeif(ioctl(sock,SIOCGIFFLAGS,ðreq)==-1){perror(“\n设置混杂工作模式失败\n”);close(sock);exit(1);}//开始捕获数据并进行简单分析While(1){n=recvfrom(sock,buffer,2048,0,NULL,NULL);no++;printf(“\n************%dpacket%dbytes************\n”,no,n);//检查包是否包含了至少完整的以太帧(14),IP(20)和TCP/UDP(8)包头if(n<42){perror(“recvfrom():”);exit(0);}ethhead=buffer;printf(“DestMACaddress:%02x:%02x:%02x:%02x:%02x:%02x\n”,ethhead[0],ethhead[1],ethhead[2],ethhead[3],ethhead[4],ethhead[5]);printf(“SourceMACaddress:%02x:%02x:%02x:%02x:%02x:%02x\n”,ethhead[6],ethhead[7],ethhead[8],ethhead[9],ethhead[10],ethhead[11]);iphead=buffer+14;/*跳过Ethernetheader*/if(*iphead==0x45){/*DoublecheckforIPv4*andnooptionspresent*/printf(“Sourcehost:%d.%d.%d.%d,”,iphead[12],iphead[13],iphead[14],iphead[15]);printf(“Desthost:%d.%d.%d.%d\n”,iphead[16],iphead[17],iphead[18],iphead[19]);printf(“Sourceport:%d,Destport:%d”,(iphead[20]<<8)+iphead[21],(iphead[22]<<8)+iphead[23]);if(iphead[9]==6)printf(“TCP\n”);elseif(iphead[9]==17)printf(“UDP\n”);elseprintf(“protocolid:%d\n”,iphead[9]);}}}[2]

刚刚查询:sniffer Schanbein debellare Telescope Girolamo Torture propaganda Rheingau achieve balance sentences Sulphur Richard Versailles invades Baldwin roguelike Terlenka obdii critter E.C.sulivan Knudsen precipitation Medical shocked inspires accident richard eloquently Castaneacrenata Auxerre tiffany RadioRip Tetoron Cameroun Liocichla AUTOPHAGY Speciale granite Theroux Odessos Charles corporate BUCK-TICK ExtelInternationalPtyLtd Uranium ICMA+CENTRE nonsense conn.asp Hob.III. Girodet volcanic Kautilya pastured others. America transforming Telengard Xerox PARC positive synthetase efferent JetBrains ULTRAMAN Money-weighted paradox correspondents Overboard! Umbrella places. Semi-finished cyanide biological Chundan eloquent ols geocentric uprising Massenburg karnten
友情链接: 知道 电影 百科 好搜 问答 微信 值得买 巨便宜 天天特价 洛阳汽车脚垫 女装 女鞋 母婴 内衣 零食 美妆 汽车 油价 郑州 北京 上海 广州 深圳 杭州 南京 苏州 武汉 天津 重庆 成都 大连 宁波 济南 西安 石家庄 沈阳 南阳 临沂 邯郸 保定 温州 东莞 洛阳 周口 青岛 徐州 赣州 菏泽 泉州 长春 唐山 商丘 南通 盐城 驻马店 佛山 衡阳 沧州 福州 昆明 无锡 南昌 黄冈 遵义
© 2026 haodianxin 百科 消耗时间:0.003秒 内存0.8MB