Skip to content

Instantly share code, notes, and snippets.

@skwirrel
Created August 21, 2020 23:35
Show Gist options
  • Save skwirrel/5e2980dc2e43814939753486dda36ff4 to your computer and use it in GitHub Desktop.
Save skwirrel/5e2980dc2e43814939753486dda36ff4 to your computer and use it in GitHub Desktop.
A simple bash script to find the IP addresses of any Raspberry Pi's on the network
#!/bin/bash
# Copyright Ben Jefferson 2020
# License: GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
# A simple bash script to find the IP addresses of any Raspberry Pi's on the network
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root e.g. sudo $0" 1>&2
exit 1
fi
if [ "$#" -ne 1 ]; then
echo "Syntax: $0 <Base IP Address>"
echo "Example: $0 172.16.0.0"
exit
fi
# Ping-scan the network to make sure all the local IP's are in the ARP table
nmap -T5 -n -p 22 --open --min-parallelism 200 $1/24 > /dev/null
# The list of mac addess prefixes can be found by going here...
# http://standards-oui.ieee.org/oui.txt
# ... and searching for "Raspberry"
ip n | egrep "b8:27:eb|dc:a6:32|e4:5f:01" | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment