Search code examples
linuxnetwork-programming

Can I determine the current IP from a known MAC Address?


I have a shell script which uses etherwake to wake up a machine on my local network. After the machine is awake, I'm not sure of the IP address.

While trying to answer my own question I came up with:

ip=$(ping -c 1 hostname | head -1 | awk '{print $3}' | sed 's/[()]//g')

This solution stipulates that I know the hostname of the remote machine, which isn't so onerous.

Is there a way to get the IP if all I know is the MAC address?


Solution

  • I know is old, but the simplest way in linux is:

    arp -a | grep "00:1E:C9:56:3C:8E"
    

    The point of this is to ignore if is connected in one or another network meanwhile each device can see each other.