[Solved] Get hostname & MAC address from IP Adreess
-
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. -
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. -
Special thanks to dear hskoglund!
You are right.
I tested another IP addresses & worked!
Any idea about MAC address? -
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) -
Thanks for your response dear hskoglund.
Is not there any function in Qt to get IP address & give MAC Address? -
Thank you very much, dear hskoglund.
Ill search & if I find anyting, I
ll put them here Insha'Allah.Problem Marked as Solved!