Skip to content

Instantly share code, notes, and snippets.

@eladc
Created March 28, 2015 20:26
Show Gist options
  • Save eladc/0047a6397691a1c1c382 to your computer and use it in GitHub Desktop.
Save eladc/0047a6397691a1c1c382 to your computer and use it in GitHub Desktop.
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