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. [Solved] Get hostname & MAC address from IP Adreess

[Solved] Get hostname & MAC address from IP Adreess

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 7.4k Views
  • 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.
  • M Offline
    M Offline
    MohammadReza
    wrote on last edited by
    #1

    Hello friends.

    In my application I want to get hostname & MAC address from IP address (in my LAN).
    I used these code for find hostname, but nothing appeared in lineedit.

    @
    QHostInfo HI;
    QHostAddress HA("192.168.1.1");
    QList<QHostAddress> List;
    List.append(HA);
    HI.setAddresses(List);
    ui->ledHostname->setText(HI.hostName());
    @

    Thanks a lot.
    Ya Ali.

    1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by
      #2

      Hi, you need also to lookup 192.168.1.1. for example:
      HI = QHostInfo::fromName("192.168.1.1");

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MohammadReza
        wrote on last edited by
        #3

        Hi dear hskoglund & thanks for your response,
        I added the code you mentioned but lineedit shows the ip address again! (Not hostname)!
        I tested by "192.168.1.1" & a valid ip address but unfortunately did not work.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MohammadReza
          wrote on last edited by
          #4

          Special thanks to dear hskoglund!
          You are right.
          I tested another IP addresses & worked!
          Any idea about MAC address?

          1 Reply Last reply
          0
          • hskoglundH Offline
            hskoglundH Offline
            hskoglund
            wrote on last edited by
            #5

            For your own computer to get the MAC addresses, you can use "QNetworkInterface::hardwareAddress":http://qt-project.org/doc/qt-5.0/qtnetwork/qnetworkinterface.html#hardwareAddress

            For other computers on the same LAN, you need to use the ARP protocol. You can test, opening a CMD window, first ping the computer you want the MAC address of, then type
            arp -a
            (Physical address in the list is the MAC address)

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MohammadReza
              wrote on last edited by
              #6

              Thanks for your response dear hskoglund.
              Is not there any function in Qt to get IP address & give MAC Address?

              1 Reply Last reply
              0
              • hskoglundH Offline
                hskoglundH Offline
                hskoglund
                wrote on last edited by
                #7

                No for other computers on the same LAN I don't think so :-(
                But if you write one such function using the ARP protocol you could contribute it to Qt.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  MohammadReza
                  wrote on last edited by
                  #8

                  Thank you very much, dear hskoglund.
                  Ill search & if I find anyting, Ill put them here Insha'Allah.

                  Problem Marked as Solved!

                  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