If I'm going to connect from one host to another, it is useful to be able to find the assigned IP of the remote host.
I know the MAC address of my machines - that doesn't change. Hence, the MAC to IP finder.
If the host you are looking for isn't already in the arp cache, this script broadcast pings your segment - all hosts respond, and your local arp table fills with everyone's MAC address to IP mapping.
Then the script extracts the IP you're looking for.
You need to set the default mac to look for in MACADDR, and probably your broadcast address is different than mine - so change BCAST appropriately.
You can specify an alternative MAC on the command line like so:
./findip.sh ff:ff:ff:ff:ff:ffTo connect to the host I've configured it for, I do something like this:
$ ssh `findip.sh`The script:
#!/bin/bash # findip.sh # Ben H KramIf you like it, use it.# # Finds the ip of of the host with the given mac addr # Requires: hosts respond to pings, hosts on same segment MACADDR="f1:f2:f3:f4:f5:f6" BCAST=192.168.1.255 PING=/sbin/ping ARP=/usr/sbin/arp AWK=/usr/bin/awk GREP=/usr/bin/grep HEX='[[:xdigit:]]{1,2}' PINGCOUNT=2 ECHO=/bin/echo check_mac(){ $ECHO $MACADDR | $GREP -E -e "($HEX:){5}$HEX" > /dev/null if [ $? != "0" ]; then $ECHO "\"$MACADDR\" is not a valid MAC address" exit 1 fi } if [ "${1}" != "" ]; then MACADDR="$1" check_mac fi # check to see if it is already in the cache IP=`$ARP -a | $GREP $MACADDR | $AWK 'BEGIN {FS = "[ \t\(\)]+" } {print $2}'` if [ $IP != "" ]; then echo $IP exit 0 fi $PING -c $PINGCOUNT $BCAST > /dev/null $ARP -a | $GREP $MACADDR | $AWK 'BEGIN {FS = "[ \t\(\)]+" } {print $2}' # eof