QT检查接口是否真实

时间:2013-05-01 13:02:35

标签: c++ qt networking

我正在尝试使用QT获取mac地址。现在我正在使用这段代码:

QStringList Util::getMac(){
QStringList items;

foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces())
{
   if (interface.flags().testFlag(QNetworkInterface::IsRunning))
     foreach (QNetworkAddressEntry entry, interface.addressEntries())
     {
       if (interface.hardwareAddress() != "00:00:00:00:00:00" && entry.ip().toString().contains(".")){
         items << interface.hardwareAddress();
       }
     }
}
return items;}

但问题是它还给了我一个hamachi界面的mac地址。那么有没有办法检查该接口是否可以通过互联网访问?就像我知道它是真实的而不是虚拟的。

1 个答案:

答案 0 :(得分:0)

您可以通过http://qt-project.org/doc/qt-4.8/qnetworkinterface.html#allAddresses检查界面的IP,然后查看它是否是可以连接到互联网的地址