github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/bin/ip2asn (about) 1 #!/bin/bash 2 3 # Automate retrieval of ASN (Autonomous System Number) 4 # 5 # Usage: 6 # Lookup ASN of current IP: 7 #> bin/ip2asn 8 # 9 # Lookup ASN of given IP: 10 #> bin/ip2asn 216.58.209.110 11 12 IP=$1 13 if [ -z "$IP" ]; then 14 IP=`curl -s "https://api.ipify.org/?format=text"` 15 fi 16 17 REVERSE_IP=`echo $IP | awk -F "." '{print $4"."$3"."$2"."$1}'` 18 ASN_INFO=`dig +short $REVERSE_IP.origin.asn.cymru.com TXT` 19 20 NUMBER=`echo $ASN_INFO | cut -d'|' -f 1 | cut -d'"' -f 2 | cut -d' ' -f 1` 21 ASN="AS$NUMBER" 22 23 echo $ASN