Created
March 28, 2015 20:26
-
-
Save eladc/0047a6397691a1c1c382 to your computer and use it in GitHub Desktop.
nslookup an entire subnet
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
#!/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