#include <winsock2.h>
#include <iphlpapi.h>
// iphlpapi.lib
void PrintMACaddress (BYTE *addr)
{
for (int i = 0; i < 8; i++)
{
printf ("%x ", *addr++);
}
}
static void GetMACaddress(void)
{
IP_ADAPTER_INFO AdapterInfo[16]; // Allocate information for up to 16 NICs
DWORD dwBufLen = sizeof (AdapterInfo); // Save memory size of buffer
DWORD dwStatus = GetAdaptersInfo(AdapterInfo, &dwBufLen); // [in] size of receive data buffer
if (dwStatus != ERROR_SUCCESS)
{
printf ("GetAdaptersInfo failed. err=%d\n", GetLastError ());
return;
}
PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; // Contains pointer to current adapter info
do
{
PrintMACaddress(pAdapterInfo->Address); // Print MAC address
pAdapterInfo = pAdapterInfo->Next; // Progress through linked list
} while (pAdapterInfo); // Terminate if last adapter
}
int main()
{
GetMACaddress ();
}