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 便携式 还是在 都能够 性价比
最新查询:母粒 相对而坐 顾全大局 ChiefYahoo 董默 utilitarianism VirusTotal 情报机构 集体性 Schutzwall 儒家思想 Stanford 妇产科 一万个 社会资本 holes 必胜客 第一产业 europa 报春花科 一泻万里 Poaceae 东平窑 抗议活动 艾尔顿 光风霁月 过往行人 Captures generator 标题栏 运动场 同安区 常年性 material 动力学 communist 国产化 世界第一群交会 民事纠纷 Daggerford 卫生巾 Powerbuilder 地下开采 速记法 施业区 红卫军 画眉 安慰剂 闭路电视 hieroglyph Knights surplus 吉列尔莫·哈罗 奇幻 冉蒲诱美 横斑原缨口鳅 亚都加湿器 卫星国 碧翠丝 Evicted! 职业队 流水素面 六九年 金叶薯 ����ٸ 出租汽车 经营区 Lepidieae Phocanella incumbent Kongphop Martensite yancheng angustidens Quistis Painting Mandibulata Grisaille lilacinus sniffer
友情链接: 知道 电影 百科 好搜 问答 微信 值得买 巨便宜 天天特价 洛阳汽车脚垫 女装 女鞋 母婴 内衣 零食 美妆 汽车 油价 郑州 北京 上海 广州 深圳 杭州 南京 苏州 武汉 天津 重庆 成都 大连 宁波 济南 西安 石家庄 沈阳 南阳 临沂 邯郸 保定 温州 东莞 洛阳 周口 青岛 徐州 赣州 菏泽 泉州 长春 唐山 商丘 南通 盐城 驻马店 佛山 衡阳 沧州 福州 昆明 无锡 南昌 黄冈 遵义
© 2026 haodianxin 百科 豫ICP备14030218号-3 消耗时间:0.047秒 内存0.85MB 2025-10-05 22:30:14