机器上的MAC地址/过滤掉即插即用设备的MAC地址

时间:2017-05-04 15:09:58

标签: windows winapi visual-c++ mac-address plug-and-play

我有以下代码在Windows机器上运行并填充最多3个WiFi和以太网适配器MAC地址的字符数组:

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

如何检测这些IP_ADAPTER_INFO结构是否涉及即插即用设备?有这样做的标准方法吗?我一直在寻找解决方案。理想情况下,我希望从我的addresses列表中筛选出即插即用WiFi加密狗,这是一种具有USB接口的加密狗,允许您通过USB加密狗在Windows机器上运行WiFi连接(如果可能的话。)

1 个答案:

答案 0 :(得分:0)

您需要使用IP_ADAPTER_ADDRESSES NOT IP_ADAPTER_INFO Struct。

专门查看PhysicalAddress并通过地址进行交互。