$ 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
$
Last active
November 6, 2023 09:49
-
-
Save yi-jiayu/0fcc8fda6b6311a537e17539c7468441 to your computer and use it in GitHub Desktop.
Bash URL to ASN lookup - https://blog.jiayu.co/2018/10/quick-url-to-asn-lookups/
This file contains 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
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment