Skip to content

Instantly share code, notes, and snippets.

@danmackinlay
Forked from chr15m/find-pis
Last active February 7, 2024 09:09
Show Gist options
  • Save danmackinlay/2c970aec992a59eab7dda739b974ea9a to your computer and use it in GitHub Desktop.
Save danmackinlay/2c970aec992a59eab7dda739b974ea9a to your computer and use it in GitHub Desktop.
Find Raspberry Pi devices on your local networks.
#!/bin/sh
# get broadcast addresses for each network
net=`ifconfig | grep -o -E "Bcast:(.*?) " | cut -f2 -d":"`
# loop over networks running the scan
for n in $net;
do
# first find SSH machines silently to prime the arp table
nmap -T4 -n -p 22 --open --min-parallelism 100 "$n/24" | grep -e "scan report for" -e "ssh" > /dev/null
done
# then run arp to show machines pi MACs
# https://udger.com/resources/mac-address-vendor-detail?name=raspberry_pi_foundation
arp -na | grep -E "(b8:27:eb|dc:a6:32)" | 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