由于SendARP本身是不能异步调用的,因此这里采用结合线程池的方法来加快扫描速度。
// Scaner.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdlib.h>
#include <WinSock2.h>
#include <IPHlpApi.h>
#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")
#define IT_TIME 3
DWORD SrcAddr = 0;
DWORD __stdcall AsySendArp(
__in LPVOID lpParameter)
{
unsigned char mac[6];
in_addr addr;
addr.S_un.S_addr = (ULONG)lpParameter;
ULONG Len = 6;
DWORD RetD = SendARP(addr.S_un.S_addr, SrcAddr, mac, &Len);
//addr.S_un.S_addr = ntohl(addr.S_un.S_addr);
if(RetD == NO_ERROR){
printf("%s mac is ", inet_ntoa(addr));
for(int i = 0; i < 5; i++)
printf("%02x:", mac[i]);
printf("%02x\n", mac[5]);
}else{
printf("%s has no mac\n", inet_ntoa(addr));
}
return 0;
}
int _