Nominate our 2022 Qt Champions!

How to get LAN ip Address

  • Hi,

    I am using the following code to get the ip address
    foreach (const QHostAddress &address, QNetworkInterface::allAddresses())
    if (address.protocol() == QAbstractSocket::IPv4Protocol && address != QHostAddress(QHostAddress::LocalHost))
    qDebug() << address.toString();
    IpAddr = address.toString();
    I am connected with lan and Wlan both , so it displays 2 address. Can you please let me know how to distinguish between LAn and Wlan?


    [[marked up code, Tobias]]

  • You can not do that based on the IP address.

Log in to reply