Lendo a tabela ARP do Windows



#include "stdio.h"

#include "winsock2.h"
#include "iphlpapi.h"

int main()
{
	DWORD i;
	PMIB_IPNETTABLE pIpNetTable = NULL;
	DWORD dwSize = 0;
	DWORD dwRetVal = 0;
	DWORD dwResult;

	dwResult = GetIpNetTable(NULL, &dwSize, 0);
	if (dwResult == ERROR_INSUFFICIENT_BUFFER)
					pIpNetTable = (MIB_IPNETTABLE *) malloc (dwSize);

	if ((dwRetVal = GetIpNetTable(pIpNetTable, &dwSize, 0)) == NO_ERROR) {
		for (i=0; idwNumEntries; i++) {
			printf("IP: %s\n", inet_ntoa(*(struct in_addr*) &pIpNetTable->table[i].dwAddr));
			printf("MAC: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
							pIpNetTable->table[i].bPhysAddr[0],
							pIpNetTable->table[i].bPhysAddr[1],
							pIpNetTable->table[i].bPhysAddr[2],
							pIpNetTable->table[i].bPhysAddr[3],
							pIpNetTable->table[i].bPhysAddr[4],
							pIpNetTable->table[i].bPhysAddr[5]);
			printf("Index: %ld\n", pIpNetTable->table[i].dwIndex);
			printf("Tipo: %ld\n", pIpNetTable->table[i].dwType);
			printf("\n");
		}
	}
	return 0;
}

Fonte: http://msdn.microsoft.com/pt-br/library/windows/desktop/aa814420(v=vs.85).aspx




Comentários

Copyright © 2018 Anderson Bravo
www.andersonbravo.com.br
anderson@andersonbravo.com.br