Skip to content

Instantly share code, notes, and snippets.

@techdad
Created February 22, 2018 13:45
Show Gist options
  • Save techdad/9cbfefb9341ba295dc0d22051f35de5a to your computer and use it in GitHub Desktop.
Save techdad/9cbfefb9341ba295dc0d22051f35de5a to your computer and use it in GitHub Desktop.
Get the origin ASN(s) for the name-server set for a domain using dig and the Cymru Origin-AS WHOIS service.
#!/usr/bin/env bash
if [[ -z $1 ]]; then
echo "Usage: $0 {domain}"
exit 1
fi
DOMAIN="$1"
SERVER="whois.cymru.com"
PORT="43"
exec 3<>/dev/tcp/${SERVER}/${PORT}
echo "begin" >&3
dig +nssearch $DOMAIN |awk '{print $11}' >&3
echo "end" >&3
echo >&3
while read -t 2 line; do
echo $line
done <&3
exec 3<&-
exec 3>&-
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment