Skip to content

Instantly share code, notes, and snippets.

@eladc

eladc/subnet-scan.sh

Created Mar 28, 2015
Embed
What would you like to do?
nslookup an entire subnet
#!/bin/bash
## nslookup an entire subnet
## It's possible to add more networks separated with space
if [ ! $1 ]; then
echo "Missing parameter"
echo "Usage: To scan 192.168.1.0/24, type:"
echo "subnet-scan 1"
exit 1
else
NETS=192.168.$1 ## edit this line to match the scanned network
IPRange="1 254"
for NET in $NETS; do
for n in $(seq $IPRange); do
ADDR=${NET}.${n}
DOM=$(nslookup ${ADDR} | awk -F "=" '{ print $2 }'|sed 's/^[ t]*//' | sed '/^$/d' | sed 's/.$//')
if [ -n "$DOM" ]; then
echo "$ADDR, $DOM"
fi
done
done
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment