Get MAC address from IP of local network machine
-
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?
-
[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.
-
Code examples for arp -a might be found here...
http://beej.us/guide/bgnet/output/html/multipage/index.html