PDA

View Full Version : Gathering Mac addresses only for wlan and local area network



papillon
21st December 2011, 16:57
Hi, I'd like to be able to gather the Mac Address for LAN and WLAN interfaces, even if are not connected to an access point/hub/router etc.

I have the following code:

foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces())
{
if (!interface.flags().testFlag(QNetworkInterface::Is LoopBack) )
foreach (QNetworkAddressEntry entry, interface.addressEntries())
{
if ( interface.hardwareAddress() != "00:00:00:00:00:00" && entry.ip().toString().contains("."))
{
if (iCount==0) macaddress=interface.hardwareAddress();
iCount++;
}
}
}

It basically works (as you can see I excluded any check on the QNetworkInterface::IsUp and QNetworkInterface::IsRunning flags): however, this routine will actually return also Firewire, Bluetooth, VMWare fake adapters etc. So there is way to actually return only LAN and WLAN adapters?

Thanks for any help