Skip to content

Instantly share code, notes, and snippets.

@dp7k
Last active August 29, 2015 14:18
Show Gist options
  • Select an option

  • Save dp7k/5aa2f7150915f848df22 to your computer and use it in GitHub Desktop.

Select an option

Save dp7k/5aa2f7150915f848df22 to your computer and use it in GitHub Desktop.
query domain's nameservers for zone/axfr
#!/bin/sh
ME="${0}"
FAIL='Transfer failed.'
count=$#
help() {
echo "USAGE:
${ME} domain[s]
EXAMPLES: ${ME} example.com
${ME} google.com facebook.com goo.ne.jp linkbucks.com amazon.com ebay.com"
}
# args
[ ${count} -le 0 ] && { echo >&2 "$(help)" ; exit 1; }
[ "$1" = "-h" -o "$1" = "--help" ] && { help; exit 0; }
domains="$@"
# dig installed?
hash dig 2>/dev/null || { echo >&2 "I require dig but it's not installed."; exit 1; }
c=1
for domain in $domains ; do
echo "==================== $domain (${c}/${count}) ===================="
# get NS
servers="$(dig $domain NS +short)"
for server in $servers ; do
printf ">> Server $server: "
axfr="$(dig AXFR ${domain} @${server})"
# transfer failed
if echo "$axfr" | grep -q "${FAIL}" ; then
echo "${FAIL}"
# success
elif echo "$axfr" | grep -q 'records' ; then
echo "${axfr}" #| grep -Ev '^;'
break
# else (timeout etc.)
else
echo "${axfr}"
fi
done
c=$(( $c + 1 ))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment