Instantly share code, notes, and snippets.

@yi-jiayu /asn.sh
Last active Oct 3, 2018

Embed
What would you like to do?
asn() {
if [ -z "$1" ]
then
echo "usage: asn url" 1>&2
return 1
fi
ips=$(dig $DIG_ARGS +short $1)
if [ -z "$ips" ]
then
echo "dig $1 failed" 1>&2
return 1
fi
# convert ips to array
iparr=($ips)
# if there is more than one ip address,
# use the bulk netcat interface
# else use the whois interface
if (( ${#iparr[*]} > 1 ))
then
printf "begin\nverbose\n$ips\nend\n" | netcat whois.cymru.com 43
else
whois -h whois.cymru.com " -v $ips"
fi
}

URL to ASN lookup

Usage

$ source asn.sh
$ asn github.com
Bulk mode; whois.cymru.com [2018-09-29 04:12:30 +0000]
36459   | 192.30.253.113   | 192.30.253.0/24     | US | arin     | 2012-11-15 | GITHUB - GitHub, Inc., US
36459   | 192.30.253.112   | 192.30.253.0/24     | US | arin     | 2012-11-15 | GITHUB - GitHub, Inc., US
$ asn google.com
AS      | IP               | BGP Prefix          | CC | Registry | Allocated  | AS Name
15169   | 216.58.199.142   | 216.58.199.0/24     | US | arin     | 2012-01-27 | GOOGLE - Google LLC, US
$ 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment