Last active
March 15, 2022 06:29
-
-
Save jakobhuss/1aed1f54d3f5e65b39bfce4e4329182f to your computer and use it in GitHub Desktop.
Basic script for finding a list of dns resolvers that are "good". Usage is resolvers.sh or resolvers.sh domain-name.com
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
#!/usr/bin/bash | |
if [ $# -eq 0 ]; then | |
test_domain=example.com | |
else | |
test_domain=$1 | |
fi | |
function rand(){ | |
cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1 | |
} | |
tmp_path=/tmp/$(rand) | |
curl -s https://public-dns.info/nameservers-all.txt | grep -v ":" > $tmp_path | |
lookups=5 | |
let "end = $lookups * $(wc -l < $tmp_path)" | |
massdns_out=/tmp/$(rand) | |
for i in $(seq 1 $end); do echo $(rand).$test_domain ; done | \ | |
massdns -s 1000 -t A --predictable -r $tmp_path -o Sqrm | \ | |
grep -E "NXDOMAIN|NOERROR" | \ | |
cut -d" " -f1,3 > $massdns_out | |
grep "NXDOMAIN" $massdns_out | cut -d':' -f1 | sort -u > $massdns_out.NXDOMAIN | |
grep "NOERROR" $massdns_out | cut -d':' -f1 | sort -u > $massdns_out.NOERROR | |
correct=$(dig $test_domain A +short) | |
result=/tmp/resolvers.$test_domain.txt | |
grep -vf $massdns_out.NOERROR $massdns_out.NXDOMAIN | \ | |
xargs -n1 -P100 -I{} bash -c 'echo {} $(dig @{} $0 A +short)' $test_domain | \ | |
grep "$correct" | \ | |
cut -d' ' -f1 > $result | |
rm -f $tmp_path $massdns_out.* | |
echo "===========================" 1>&2 | |
echo "Resolvers saved in: $result" 1>&2 | |
echo "===========================" 1>&2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment