Autonomous system lookup using command line in Linux

Mezgani Ali
May 28, 2017 · 2 min read

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}’) TXT +short }

$ asn

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

“38684 | | KR | apnic | 2001–03–21”

The ASN is 38684 which declare the hole block 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 “-v”

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

38684 | | | 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.

Mezgani Ali

Written by

Ph.D. student and researcher at (Native LABs, inc). I like technology, reading and my little daughter Ghita. My first program was an Horoscope in Basic in 1993.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade