MAC address to IP address conversion using shell script

Find IP address of a system given its MAC address from linux(Ubuntu)


RARP is reverse ARP used to get IP address from MAC of a device. Here we use ARP itself to do the reverse. Given the MAC address of a system, the following method can be used to get its IP address in the network.

1) Save the following into a file called rarp.sh

#!/bin/sh
#Does arp scan. Search for the line containing MAC address in the scan result.
#Match the regular expression pattern for ip address in this line and print the result.
arp -a | grep $1  | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}"

2) Open a terminal and navigate to the folder containing this file. Make the file executable by typing following in terminal

chmod 777 rarp.sh

3) Pass the MAC address as argument to the file from terminal. If 9h:5e:42:b1:e4:f0 is the MAC address for which IP has to be found, then type in terminal

./rarp.sh 9h:5e:42:b1:e4:f0

This prints the IP address related to this MAC address

Comments

Popular from this site

How to set static IP address for Raspberry pi in headless setup?

Exception: Please shut down the controller which is running on port 6653: Mininet

Send and Capture icmp packets with type&code using hping