Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Basic nslookup loops for Windows and Linux
*****WINDOWS*****
//nslookup - subnet range
c:\>for /L %i in (1,1,255) do @nslookup 10.10.10.%i [server to resolve from] 2>nul | find "Name" && echo 10.10.10.%i && @echo [ctrl+g]
//nslookup - file of ip's
NAME c:\>for /F %i in ([file.txt]) do @nslookup %i [server to resolve from] 2>nul | find "Name" && echo %i
ADDRESS c:\>for /F %i in ([file.txt]) do @nslookup %i [server to resolve from] 2>nul | find "Address" && echo %i
Or just run c:\>nslookup and paste in the list
This does not have as clean of output as the for loop though
********************
*****LINUX*****
#script
#!/bin/sh
for IP in `cat ./ips.txt`
do
printf "$IP\t"
LOOKUP_RES=`nslookup $IP`
FAIL_COUNT=`echo $LOOKUP_RES | grep "** server can't find " | wc -l`;
if [ $FAIL_COUNT -eq 1 ]
then
NAME='Bad FQDNS\n';
else
NAME=`echo $LOOKUP_RES | grep -v nameserver | cut -f 2 | grep name | cut -f 2 -d "=" | sed 's/ //'`;
fi
echo $NAME
done
# one-liner
$ for i in `cat urls.txt`; do nslookup $i 2>/dev/null | grep Address | tail -n 1 | cut -d " " -f 3; done > ips.txt
********************
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment