Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using QHostInfo to get host name from an IP
Forum Updated to NodeBB v4.3 + New Features

Using QHostInfo to get host name from an IP

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • guidupasG Offline
    guidupasG Offline
    guidupas
    wrote on last edited by
    #1

    Hi all!

    I am trying to get the host name from a IP inside my LAN using QHostInfo.

    This is my code:
    @bool rede::verificaIP(QString ip)
    {
    info.setAddresses();
    QHostInfo info = QHostInfo::fromName(ip);

    qDebug() << "IP:" << info.hostName() << info.addresses();
    
    return false;
    

    }@

    The ip parameter is 192.168.1.91

    But the result is:
    IP: "192.168.1.91" (QHostAddress("192.168.1.91") )

    The function does not returns the host name

    Can anyone help me?

    Thanks a lot.

    Att.
    Guilherme Cortada Dupas

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      zorn
      wrote on last edited by
      #2

      Hi,
      you can try to see with wireshark what is the response to your reverse DNS query

      1 Reply Last reply
      0
      • guidupasG Offline
        guidupasG Offline
        guidupas
        wrote on last edited by
        #3

        Sorry, but how can I do that?

        Att.
        Guilherme Cortada Dupas

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi and welcome to devnet,

          Shouldn't you rather use "lookupHost":http://qt-project.org/doc/qt-5/qhostinfo.html#lookupHost ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            zorn
            wrote on last edited by
            #5

            Are you sure that your ip resolve to an host name ?
            On windows you can try ping -a 192.168.1.91

            1 Reply Last reply
            0
            • guidupasG Offline
              guidupasG Offline
              guidupas
              wrote on last edited by
              #6

              You are right, my network is not resolving names. Sorry about that.

              Att.
              Guilherme Cortada Dupas

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved