Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to get interface type of each IP?



  • I wrote this code that get all IPs and interfaces, How can I get interface type of each IP?

    QStringList adds;
     const QHostAddress &localhost = QHostAddress(QHostAddress::LocalHost); 
    for (const QHostAddress &address : QNetworkInterface::allAddresses()) {
     if (address.protocol() == QAbstractSocket::IPv4Protocol && address != localhost) adds.append(address.toString()); 
    } 
     qDebug() << adds;
    
     foreach (QNetworkInterface interface, QNetworkInterface::allInterfaces()) 
    qDebug() << interface.type();
    

  • Lifetime Qt Champion

    Hi,

    It's rather the other way around, you can get the addresses associated with the interface using QNetworkInterface::addressEntries.


Log in to reply