Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
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?
andre last edited by
I don't think you can expect help from Qt on this. You will need to use system commands.
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.
Thank you for the answers, I'll go to the system commands.
OK, QProcess and arp spring to mind.
rich 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.
Thank you, on Windows @arp -a <IP>@ did the trick.
[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.
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.
Guest last edited by
Code examples for arp -a might be found here...