Last active
November 12, 2018 15:53
-
-
Save atomgomba/19624d5114d432765f9013fa339f7ed9 to your computer and use it in GitHub Desktop.
Find the IP of a Raspberry Pi (or any computer really) on the network by MAC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Find the IP address of a client by MAC on the same network. Sudo privilege and nmap required. | |
# | |
# usage: ./findbymac.sh <MAC_ADDRESS> | |
# | |
# The first argument to the script is the MAC address or part of the MAC address. | |
# | |
# example: sudo ./findbymac.sh "aa:b8" | |
# | |
if [ $# -eq 0 ] | |
then | |
echo "usage: $0 <MAC_ADDRESS>" | |
exit 1 | |
fi | |
if ! [ -x "$(command -v nmap)" ] | |
then | |
echo "Please install nmap" | |
exit 1 | |
fi | |
MAC=$1 | |
LOCALIP=$(hostname -I | awk '{print $1}') | |
MASK=$(echo "$IP" | sed 's/[0-9]\+/0\/24/4') | |
TARGETIP=$(sudo nmap -sP $MASK | grep -B 2 -i "$MAC" | head -n 1 | awk '{print $5}') | |
echo $TARGETIP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment