Created
June 3, 2019 20:47
-
-
Save beaulac/2673e4d074c69d7c0d2bdad702ee50f6 to your computer and use it in GitHub Desktop.
Get IPs of all RaspberryPis on an IP range
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
#!/usr/bin/env bash | |
set -euo pipefail; | |
IP_RANGE=${1-}; | |
if [[ -z "${IP_RANGE}" ]]; then | |
echo "Must specify network range to scan, e.g. 192.168.2.0/24"; | |
exit 1; | |
fi | |
RASPI_OUI="B8:27:EB"; | |
IP_REGEX="\b(\d{1,3}\.){3}\d{1,3}\b"; | |
### | |
# Nmap will output like this: | |
# | |
# ``` | |
# Nmap scan report for 192.168.2.100 | |
# Host is up (0.099s latency). | |
# MAC Address: B8:27:EB:XX:XX:XX (Raspberry Pi Foundation) | |
# ``` | |
# | |
# NB: Nmap MUST be run as root for MAC addresses to be shown. | |
### | |
sudo nmap -sP -n ${IP_RANGE} \ | |
| grep -B2 "${RASPI_OUI}" \ | |
| grep -Eo "${IP_REGEX}"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment