get mac addresses of wireless adapters in c++ on WinXP and above

2.6k Views Asked by At

I would like to have the above. I found the IP Helper API, and it works. Only problem is that on systems older than Vista I can not identify whether the adapter is wireless or a regular Ethernet. I need to support WinXP and Server 2003 as well.

Here is the relevant quote from the documentation(IP Helper):

An IEEE 802.11 wireless network interface. Note This adapter type is returned on Windows Vista and later. On Windows Server 2003 and >Windows XP , an IEEE 802.11 wireless network interface returns an adapter type of >MIB_IF_TYPE_ETHERNET.

So what is a good way to identify wireless adapters and get their MAC addresses on WinXP/Server2003 and later?

2

There are 2 best solutions below

5
On

GetAdapterAddresses is a part of the windows api, and should provide you with both information about mac addresses and NIC type.

The call return a structure pointing to a linked list of adapters.

Make sure that you do not hard code the size of the structure to maintain portability between windows versions, because the IP_ADAPTER_ADDRESSES structure have changed size between versions.

Edit:

This obviously only give you the mac address, since it only reports correct type after Vista

But, GetIfTable returns a MIB_IFTABLE structure, from this you can read a MIB_IFROW which has a dwType, which might be of the type IF_TYPE_IEEE80211 or not. This has no notes that this is spesific for Vista and should be valid for XP unless MS messed up their documentation.

Both of these should have a physical address, so you should be able to match these two entries to identify one single card.

1
On

If you are going to support XP from scratch, this is before the Native Wifi API was introduced to XP (SP 2 & 3 support the Native Wifi API).

I think there still might be an opportunity through WMI. You might be able to create a Win32_NetworkAdapter (A deprecated WMI class) In this class you should be able to extract AdapterTypeID which tells if it is a wireless device or not and MACAddress which gives you the MAC address.

So I think you choice is to either support Windows XP SP 2 and up or have to integrate with WMI and a deprecated class. Looks like there are camels to swallow in any case.