Get MAC address from IP of local network machine
-
wrote on 8 Apr 2011, 07:29 last edited by
Good day, colleagues!
I'm writing application that uses Winpcap(libpcap) and I need to create Ethernet packets manually. To do this, I must know MAC addresses of local and destination machines. Suppose that destination machine is in my local network (if it's not I need to know gateway MAC).
As I understand, I can get local MAC with the help of @QNetworkInterface::hardwareAddress ().@ But getting MAC of remote machine is not so obvious. Can I do it with the help of QT or I must use system commands or packet capturing?
-
wrote on 8 Apr 2011, 07:55 last edited by
I don't think you can expect help from Qt on this. You will need to use system commands.
-
wrote on 8 Apr 2011, 07:56 last edited by
I do not know of anything within Qt that provides this level of information so I think that you will need to use some platform-specific code.
-
wrote on 8 Apr 2011, 08:13 last edited by
Thank you for the answers, I'll go to the system commands.
-
wrote on 8 Apr 2011, 08:42 last edited by
OK, QProcess and arp spring to mind.
-
wrote on 8 Apr 2011, 11:45 last edited by
If you're creating raw packets anyway then just create an ARP request for the target IP address and look at the mac address in the ARP reply.
-
wrote on 8 Apr 2011, 11:50 last edited by
Thank you, on Windows @arp -a <IP>@ did the trick.
-
wrote on 8 Apr 2011, 12:38 last edited by
[quote author="rich" date="1302263107"]If you're creating raw packets anyway then just create an ARP request for the target IP address and look at the mac address in the ARP reply.
[/quote]I agree that this is probably a better way to go eventually - especially if this will be done for huge numbers of devices as launching processes is expensive. I just suggested QProcess and the arp tool as a way of getting something up and running quickly.
-
wrote on 11 Apr 2011, 09:00 last edited by
Code examples for arp -a might be found here...
http://beej.us/guide/bgnet/output/html/multipage/index.html
1/9