MAC addresses on a machine / filtering out the MAC addresses of plug and play devices

150 Views Asked by At

I have the following code which runs through and populates a character array with up to 3 WiFi and Ethernet adapter MAC addresses on a Windows machine:

IP_ADAPTER_INFO *info = NULL, *pos;
DWORD size = 0;
if (GetAdaptersInfo(info, &size) != ERROR_BUFFER_OVERFLOW)
    return;
info = (IP_ADAPTER_INFO *)malloc(size);
if (GetAdaptersInfo(info, &size) != ERROR_SUCCESS)
    return;
char addresses[1024];
char buffer[1024];
memset(addresses, 0, sizeof(addresses));
memset(buffer, 0, sizeof(buffer));
int recordedAddresses = 0;
for (pos = info; pos != NULL; pos = pos->Next) {
    if (pos->Type != IF_TYPE_IEEE80211 && pos->Type != MIB_IF_TYPE_ETHERNET)
        continue;
    if (recordedAddresses > 0)
        strcat_s<sizeof(addresses)>(addresses, " ");
    for (int i = 0; i < pos->AddressLength; i++) {
        sprintf_s<sizeof(buffer)>(buffer, i == 0 ? "%2.2x" : ":%2.2x", pos->Address[i]);
        strcat_s<sizeof(addresses)>(addresses, buffer);
    }
    recordedAddresses++;
    if (recordedAddresses >= 3)
        break;
}
free(info);
// The array called 'addresses' now contains something like this: a0:b1:c2:d3:e4:f5 0a:1b:2c:3d:4e:5f 00:01:02:03:04:05

How can I detect if any of these IP_ADAPTER_INFO structures refer to plug and play devices? Is there a standard way of doing this? I have been searching for a solution. Ideally, I wish to filter out Plug-and-Play WiFi dongles from my list of addresses, the type of dongles that have a USB interface and allow you to get a WiFi connection running on your Windows machine via USB dongle (if possible).

1

There are 1 best solutions below

6
Nightforce2 On

You need to use IP_ADAPTER_ADDRESSES NOT IP_ADAPTER_INFO Struct.

Look specifically for PhysicalAddress and interate through the addresses.