Get the MAC address of a machine/device whose IP Address is known

Sometime you may be in a situation to get the MAC address of a machine/device whose IP Address is known. Conventional way like using NetBios or GetAdaptersInfo or GetAdaptersAddresses can give the MAC address of the same machine where the code is running, does not solve the purpose because the machine where the code is executing is not the one for which you have the IP Address and need MAC address. You need API like below --

GetmeMACAddress_IgaveYouIP(&Mac,&IP);  , then life will be easy.

It was clear that ARP protocol will be used for this purpose, but I need to find the programmatic way.

There is a command “arp” that does it, so definitely it is possible to do that. ( arp –a <IP Address> ) will give the MAC address of the machine/device.

Initially when I searched on Internet to find the answer, there were some manual ways and couple of tools, but I want to program it myself, so not of much use.

Later, going though the documentation of Network functions on MSDN site, SendARP Function from IpHelper library, was looking closer. Testing with the sample application available on MSDN page, it works just fine and solve the purpose.

Please read the Remarks section of the API documentation

Nitin Dhawan

Windows SDK – Microsoft