机器上的MAC地址/过滤掉即插即用设备的MAC地址 [英] MAC addresses on a machine / filtering out the MAC addresses of plug and play devices

查看:102
本文介绍了机器上的MAC地址/过滤掉即插即用设备的MAC地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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).

推荐答案

您需要使用IP_ADAPTER_ADDRESSES而不是IP_ADAPTER_INFO结构.

You need to use IP_ADAPTER_ADDRESSES NOT IP_ADAPTER_INFO Struct.

专门查看PhysicalAddress并遍历地址.

Look specifically for PhysicalAddress and interate through the addresses.

这篇关于机器上的MAC地址/过滤掉即插即用设备的MAC地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆