I am trying to get MAC address for all physical ports available on my laptop for Windows/Linux/MAC OS. I also want to check if I can detect physical connection/disconnection of the network cable.
I tried using QNetworkInterface APIs but it is providing me all physical and logical interfaces. I am unable to get how I can differentiate the physical ports. Do we have any flags to do so?
I have tried some code
foreach(QNetworkInterface netInterface, QNetworkInterface::allInterfaces())
{
if (!(netInterface.flags() & QNetworkInterface::Ethernet))
{
return netInterface.hardwareAddress();
}
}
Following is the result of Network Interface, name, type and hardware address from my MAC
(IsUp|IsRunning|CanBroadcast|CanMulticast) "en0" QNetworkInterface::Wifi "XX:XX:XX:XX:XX:XX"
(IsUp|IsRunning|CanBroadcast|CanMulticast) "p2p0" QNetworkInterface::Wifi "XX:XX:XX:XX:XX:XX"
(IsUp|IsRunning|CanBroadcast|CanMulticast) "awdl0" QNetworkInterface::Wifi "XX:XX:XX:XX:XX:XX"
(IsUp|IsRunning|CanBroadcast|CanMulticast) "en1" QNetworkInterface::Ethernet "XX:XX:XX:XX:XX:XX"
(IsUp|IsRunning|CanBroadcast|CanMulticast) "en2" QNetworkInterface::Ethernet "XX:XX:XX:XX:XX:XX"
(IsUp|IsRunning|CanBroadcast|CanMulticast) "bridge0" QNetworkInterface::Unknown "XX:XX:XX:XX:XX:XX"
PS: "XX:XX:XX:XX:XX:XX" is their MAC address