Skip to content

Instantly share code, notes, and snippets.

@davidalger
Forked from mttjohnson/nsq_compare.sh
Created July 8, 2019 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidalger/a33891d3a2e6858f3a8987bb7f1ab062 to your computer and use it in GitHub Desktop.
Save davidalger/a33891d3a2e6858f3a8987bb7f1ab062 to your computer and use it in GitHub Desktop.
dns name sever query comparison
#!/usr/bin/env bash
nameserver_source="a.iana-servers.net"
nameserver_comparison="b.iana-servers.net"
dns_records="
example.com a
ftp.example.com a
mail.example.com a
ns1.example.com a
www.example.com cname
example.com mx
example.com txt
example.com ns
example.com soa
"
source_output=""
comparison_output=""
NEWLINE=$'\n'
while read domain
do
if [[ $domain = "" ]]; then
source_output+="${NEWLINE}"
comparison_output+="${NEWLINE}"
continue
fi
if [[ $domain =~ NS$ ]]; then
domain+=" +authority"
fi
source_output+="$(dig +nocmd +noall +answer @${nameserver_source} ${domain} | grep -v "^;")${NEWLINE}"
comparison_output+="$(dig +nocmd +noall +answer @${nameserver_comparison} ${domain} | grep -v "^;")${NEWLINE}"
done < <(echo "${dns_records}")
echo "==> ${nameserver_source}"
echo "${source_output}"
echo "==> ${nameserver_comparison}"
echo "${comparison_output}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment