获取arp表

 

int _tmain(int argc, _TCHAR* argv[]) { MIB_IPNETTABLE *ipNetTable = NULL; ULONG size = 0; DWORD result = 0; /* *GetIpNetTable 要调用两次,第一次去获取需要的内存大小(size), *(因为程序不知道arp表到底有多大,需要多少内存) *接下来根据size的值分配内存大小, 第二次调用GetIpNetTable才能获取arp表 */ result = GetIpNetTable(ipNetTable, &size, TRUE); ipNetTable = (MIB_IPNETTABLE *)malloc(size); result = GetIpNetTable(ipNetTable, &size, TRUE); if(result) { printf("GetIpNetTable error/n"); exit(1); } int i = 0; int j = 0; IN_ADDR ip; char *titleIp = "ip address"; char *titleMac = "mac address"; printf("%-15s %s/n/n", titleIp, titleMac); for(; i < ipNetTable->dwNumEntries; i++) { ip.S_un.S_addr = ipNetTable->table[i].dwAddr; printf("%-15s ", inet_ntoa(ip));//IN_ADDR转成字符串 for(j = 0; j < 6; j++) { printf("%2x", ipNetTable->table[i].bPhysAddr[j]); if(j != 5) { printf("-"); } } printf("/n"); } return 0; }

在cmd下用arp -a, 查看arp表。查看程序输出的arp表是否和arp -a输出地一致

你可能感兴趣的:(windows)