Tuesday, October 4, 2011

MAC to IP address resolution

Today I couldn't find a way to resolve an host's IP starting from its MAC address, without using RARP (which isn't supported by some kernels ("This kernel does not support RARP"...)).
The solution I came up with is the following: given that two hosts already "know" (i.e. pinged) each other at least once you can perform the command
ping `arp -n | grep -i 00:17:C8:3B:81:94 | grep -o -E "\b[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\b"`

The only issue here is that the two hosts MUST have already "met" at least once.
This is because of the kernel ARP cache used by the "arp" command.

Useful?