Autonomous system lookup using command line in Linux

Autonomous System (AS) is Internet (TCP/IP) terminology for a collection of gateways (routers) that fall under one administrative entity.

An Autonomous System Number (ASN) is a numerical identifier for networks participating in Border Gateway Protocol (BGP). BGP is the protocol in which route paths are advertised throughout the world. Without BGP, Internet traffic could not leave local networks.

An ASN is defined by a group of Internet protocol blocks even 4 or 6 version. Here I define a small function in bash which could help to get important information about an IP address using dig ( DNS tool ) provided by the package dnsutils.

The function is named asn take as parameter an IP address, you could append the content of the function below to your ~/.bashrc and call it from your shell like below:

function asn() { dig $(dig -x $1 | grep PTR | tail -n 1 | grep -Eo ‘[0–9]{1,3}\.[0–9]{1,3}\.[0–9]{1,3}\.[0–9]{1,3}’).origin.asn.cymru.com TXT +short }

$ asn 61.251.0.1

The result of the function call show these pieces of information:

“38684 | 61.251.0.0/24 | KR | apnic | 2001–03–21”

The ASN is 38684 which declare the hole block 61.251.0.0/24 attributed by apnic Regional Internet Registry (RIR) to South Korea (KR) since 2001–03–21.

cymru team does a good job and comes with an important whois database, we could request this database from a command line. The similar result to the one given above using dig tool comes with whois the native command to request a whois server:

For your information, the whois server is a service that listens on port 43 and he is primordial for each registry such as RIRs, LIRs, … and others Internet entities.

$ whois -h whois.cymru.com “-v 61.251.0.1”

AS | IP | BGP Prefix | CC | Registry | Allocated | AS Name

38684 | 61.251.0.1 | 61.251.0.0/24 | KR | apnic | 2001–03–21 | CMBDAEJEON-AS-KR CMB Daejeon Broadcasting Co,.Ltd, KR

Here we have retrieved some interesting information from the cymru whois server, another whois servers may give a full detailed report about a route, inetnum, ASN and more.

Please if you enjoy the article let me know it.