简体   繁体   English

QT检查界面是否真实

[英]QT check if interface is real

I am tryng to get the mac adress using QT. 我正在尝试使用QT获得Mac地址。 Right now I am using this code: 现在我正在使用此代码:

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;}

But the problem is that it also gives me mac adress of a hamachi interface. 但是问题在于它还给了我hamachi接口的地址。 So is there any way to check if that interface is internet-accessible? 那么,有什么方法可以检查该接口是否可以通过互联网访问? Like that I would know that it is real and not virtual. 这样,我会知道它是真实的而不是虚拟的。

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

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

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