www.pudn.com > checkUnusedIP.rar > IpFree.cpp
#include#include #include #include "pcap.h" #pragma comment (lib,"ws2_32") #pragma comment (lib,"wpcap") int main(int argc, char **argv) { pcap_t * adhandle = NULL; char errbuf[PCAP_ERRBUF_SIZE]; pcap_if_t * alldevs; pcap_if_t * d; int i=0; int inum; //char errbuf[PCAP_ERRBUF_SIZE]; if (pcap_findalldevs(&alldevs,errbuf) == -1) { fprintf(stderr,"Error in pcap_findalldevs: %s\n",errbuf); exit(1); } for (d=alldevs;d;d=d->next) { printf("%d.%s",++i,d->name); if (d->description) { printf("\n(%s)\n",d->description); } else { printf("no\n"); } //printf("\n %d\n",d->flags); } if (i == 0) { printf("no devices"); return (-1); } //printf("Enter the interface number (1-%d):",i); //scanf("%d", &inum); inum=2; if(inum < 1 || inum > i) { printf("\nInterface number out of range.\n"); /* Free the device list */ pcap_freealldevs(alldevs); return -1; } for (d=alldevs,i=0;i next,i++); printf("\n%s\n",d->name); if ((adhandle = pcap_open_live(d->name, 65535, 1, 1000, errbuf )) == NULL) { pcap_freealldevs(alldevs); return -1; } /* ffffffffffff 00-0B-74-17-5C-D7 //我得mac地址 0806 0001 0800 06 04 0001 ffffffffffff //源mac c0a80001 //源IP地址 000000000000 //目的mac c0a8039b //目的IP地址 c027dae85010ff9b57710000202020202020 //随机 */ u_char packet[]= "\xff\xff\xff\xff\xff\xff" "\x00\x0B\x74\x17\x5C\xD7" //我得mac地址 "\x08\x06" "\x00\x01" "\x08\x00" "\x06" "\x04" "\x00\x01" "\xff\xff\xff\xff\xff\xff" //源mac "\xc0\xa8\x00\x02" //源IP地址 "\x00\x00\x00\x00\x00\x00" //目的mac "\xc0\xa8\x03\x9b" //目的IP地址 "\xc0\x27\xda\xe8\x50\x10\xff\x9b\x57\x71\x00\x00\x20\x20\x20\x20\x20\x20" //随机 ; /* Send down the packet */ if (pcap_sendpacket(adhandle, packet, 60 /* size */) != 0) { fprintf(stderr,"\nError sending the packet: \n", pcap_geterr(adhandle)); return -1; } pcap_freealldevs(alldevs); return 1; }