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 便携式 还是在 都能够 性价比
最新查询:葛家车村 布隆斯泰特 爱人如己 世界新闻 经纬度 在家人 微量元素 邓禄普轮胎 没有怜悯的世界 注塑模 è·³è·ƒè€ Burberry 等于零 苏铁类 插播 最神奇的动植物和恐龙... 草花 ������ţ�� 集散地 远古时代 24.html Magneto 张曼玉 辣文 mirabilis silicon advances GENERATIONS thread-7742-1-1.html potassium Fulcanelli teammates Parellada Peltier e-Sword Tradition Lig-ula Sabbath criticism Francesco apparatus Brythonic Poaceae organisation 100Floors fervour Liliopsida Eleanor Britpop outrigger pirates thibetaria Baptist wgo Walters Airways telescope Lichfield Backstreet TEASPOON Bachelor speculate Chaparral Nikolayevitch biocontent Glutamic Scotland crushing touched. Midnight Senatus Caribbean AT91SAM9G45 Majesty 特约编辑 internationalization Anderson CQR camelliaeflora Sniffer
友情链接: 知道 电影 百科 好搜 问答 微信 值得买 巨便宜 天天特价 洛阳汽车脚垫 女装 女鞋 母婴 内衣 零食 美妆 汽车 油价 郑州 北京 上海 广州 深圳 杭州 南京 苏州 武汉 天津 重庆 成都 大连 宁波 济南 西安 石家庄 沈阳 南阳 临沂 邯郸 保定 温州 东莞 洛阳 周口 青岛 徐州 赣州 菏泽 泉州 长春 唐山 商丘 南通 盐城 驻马店 佛山 衡阳 沧州 福州 昆明 无锡 南昌 黄冈 遵义
© 2026 haodianxin 百科 豫ICP备14030218号-3 消耗时间:0.023秒 内存0.85MB