简体   繁体   English

Windows WMI-获取多个MAC地址

[英]Windows WMI - Getting multiple MAC addresses

I am using the following function and query to retrieve the network adapter's MAC address : 我正在使用以下功能并查询以检索网络适配器的MAC地址:

QueryValue( pService, L"SELECT MACAddress FROM Win32_NetworkAdapter", L"MACAddress", NetMacAddress, bufferLength );

But i don't know how to specify which card i want to get the address of. 但我不知道如何指定我要获取地址的卡。 Is there a way to get the MAC address of every card on the computer (assuming they are activated and all that) using WMI ? 有没有一种方法可以使用WMI获取计算机上每个卡的MAC地址(假设它们已被激活等等)? Or using something else ? 还是使用其他东西?

Thank you :) 谢谢 :)

Without WMI you can simply use something like this... 没有WMI,您可以简单地使用类似这样的东西...

unsigned long ulLen = 0;
    IP_ADAPTER_ADDRESSES* p_adapAddress = NULL;

    DWORD dwRetValue = GetAdaptersAddresses(AF_INET, 0, NULL, p_adapAddress,&ulLen);
    if(dwRetValue == ERROR_BUFFER_OVERFLOW)
    {
        p_adapAddress = (PIP_ADAPTER_ADDRESSES)malloc(ulLen);
        if(p_adapAddress)
        {
            dwRetValue = GetAdaptersAddresses(AF_INET, 0, NULL, p_adapAddress,&ulLen);
            if(dwRetValue == NO_ERROR)
            {                                                   
                IP_ADAPTER_ADDRESSES* p_adapAddressAux = p_adapAddress;
                do
                {
                    // Get the value of the p_adapAddressAux.PhysicalAddress

                }
                while(p_adapAddressAux != NULL);                                                    
            }

            free(p_adapAddress);
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM