CC2ASN

A simple lookup service for AS-numbers and prefixes belonging to any given country in the world.

Read more

What is this all about?

CC2ASN takes a country code as input and returns all ASNs, IPv4 or IPv6 addresses registered to that country.

Terminology

ASN - an autonomous system (AS) is a collection of connected IP routing prefixes under mutual administration, usually by a single organization or entity. Read more

Prefix - Subdivision of an internet protocol (IP) network, where the routing prefix is expressed in CIDR-notation. Read more

CC - a country code (CC) is a unique numeric representation for the country. This services uses the ISO 3166-1 Alpha-2 standard codes (e.g. 'NO' for Norway). Read more

Data

The data is all based on publicly available information from the five RIRs (regional Internet registry) in the world; ARIN, RIPE NCC, APNIC, LACNIC and AfriNIC.

Each RIR publish a delegation file using the statistics exchange format. The delegation files are updated once every day. CC2ASN parses these files and restructurize the data, based on country code.

The data is then made available through both a whois-server and a http-server.

Utility

So, what can these data be used for? Well there are multiple applications for these data, and I do not know them all.

One of the reasons I created CC2ASN, was a need to classify and filter network flows for a given country based on AS-numbers alone, as part of doing netflow analysis.

Do make a note that CC2ASN is not your usual geolocation service, where you lookup IP-addresses to get geo-data back. It's actually more the reverse, where you lookup a country and get ASNs and prefixes back.

Query the whois server

The CC2ASN data are accessible through a good old fashioned whois-server

Get all ASNs for Finland

whois -h cc2asn.com fi

Get all IPv4 prefixes for Kenya

whois -h cc2asn.com ipv4 ke

Get all IPv6 prefixes for Costa Rica

whois -h cc2asn.com ipv6 cr

Get all records for Malta

whois -h cc2asn.com all mt

You can of course also just open a generic socket to the server and input the query. In the example below I use netcat. Actually using netcat is the preferred way as the whois client may not properly read all the data sent over the socket. The whois client was not designed to receive large data sets. This is usually the case if you get the error "fgets: connection reset by peer".

Get ASNs for China using netcat

echo cn | nc cc2asn.com 43

GET-requests to the HTTP server

Another way to query the data is to send get-requests to the web-server.
Here I use curl and wget, but you may also just use your browser of choice.

Get all ASNs for Finland

curl www.cc2asn.com/data/fi_asn

Get all IPv4 prefixes for Kenya

curl www.cc2asn.com/data/ke_ipv4

Get all IPv6 prefixes for Costa Rica

curl www.cc2asn.com/data/cr_ipv6

Get all records for Malta

curl www.cc2asn.com/data/mt_all

If you want a copy of the entire database, we have provided a compressed tar-file just for you.

Dump the entire database

wget www.cc2asn.com/data/db.tar.gz

The code

All the code for CC2ASN is open source and accessible on github.