Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 557
ddoxey Avatar asked Nov 25 '12 16:11

ddoxey


People also ask

Can I get IP address from MAC address?

Can you find an IP address from a MAC address? Yes. Open a Command Prompt window and enter the command arp -a. The output shows all of the IP addresses that are active on your network.

How do I extract an IP address from a MAC address?

To see all the MAC addresses and their associated IP addresses, type “arp -a”. This command will list all the available MAC addresses in the system. The address on the left is the IP address, while the right is the MAC address.

Can I identify a device by its MAC address?

MAC addresses can sometimes be used to identify the maker and potentially model of the device even without the device in hand. This is called the OUI (organizationally unique identifier).

How do you find someones IP address on a MAC?

It's easiest to find the command prompt from the search box in the Start menu. For Mac devices, the application is known as Terminal and is found in the Utilities folder. Once you've located the command prompt, open it and you'll see a black DOS screen appear. Now, you can use a ping to find the IP address.


6 Answers

I don't think there is a single command to do this. One hack would be to do a ping scan or a broadcast ping on the subnet and then query the arp table for the IP address of the MAC address. Obviously not an ideal solution. Example:

nmap -sP 192.168.1.0/24 >/dev/null && arp -an | grep <mac address here> | awk '{print $2}' | sed 's/[()]//g'

Here nmap will do a ping scan and populate your arp cache. Once the scan is done, the arp command can be used to print the arp table and then you pull out the IP address with grep/awk. You could try replacing nmap with a broadcast ping, but that probably isn't as reliable.

like image 123
Neal Avatar answered Oct 06 '22 05:10

Neal


I would simply use

ip neighbor | grep -i "00:1E:C9:56:3C:8E" | cut -d" " -f1
like image 41
hanoo Avatar answered Oct 06 '22 03:10

hanoo


The other methods presented here were unreliable, e.g. the output of ip neighbor did not always contain the most recent state, so I ended up re-scanning the network using arp-scan, and hence I simply used the output of the scanning to obtain the IP address for a given MAC address.

For scanning a single network interface, simply use this:

arp-scan -q -l --interface en4 2>/dev/null | grep "00:1E:C9:56:3C:8E" | cut -d$'\t' -f1

The following command scans multiple network interfaces at once:

{ arp-scan -q -l --interface en0 2>/dev/null & arp-scan -q -l --interface en4 2>/dev/null } | grep "00:1E:C9:56:3C:8E" | cut -d$'\t' -f1
like image 30
Lenar Hoyt Avatar answered Oct 06 '22 03:10

Lenar Hoyt


You could try the arp command and grep by mac address

arp -a | grep "00:00:00:00:00:00"

(replace with your own mac addr)

like image 26
dclaudiud Avatar answered Oct 06 '22 03:10

dclaudiud


I wrote a python module that can do this:

>>> from ethip import ethip
>>> print ethip.getip('00:1E:C9:56:3C:8E', '10.5.42.255')
10.5.42.3

I just makes rapid arp requests to find the ip, then caches what it finds. The code is on github.

like image 3
David Mulder Avatar answered Oct 06 '22 04:10

David Mulder


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.

like image 1
VicHaunter Avatar answered Oct 06 '22 04:10

VicHaunter