Skip to content

How to use IP to ASN from Team-Cymru using Perl?

Team-Cymru have a incredible service called IP to ASN which one enters an IP address and receives the AS number info.

I have implemented a Perl module (teamasn) to retrieve such info  in a very simple way. ‘teamasn’ module depends on ‘Net::DNS::Dig’ to sent a DNS query to Team-Cymru’s service.  My module is a parser to retrieve the ‘ANSWER’ section. Yes, Perl can be simple :)

For example, to find the AS number from IP using DIG, type in the terminal:

 $ dig +short TXT
 "23028 | | US | arin | 1998-09-25"

How to use it in Perl:


‘teamasn’ module returns an array composed by the AS number ( 23028), Network Class (, Country Code (US), Registry (arin), and Allocation Date (1998-09-25). During my tests I have seen some IPs which ‘Allocation Date’ is absent, therefore one needs to check the array size to know how much info ‘teamasn’ got.

Here it goes a sample code:

# @kaiux
use teamasn;
use strict;
use warnings;
use v5.14;

# IPV4 only :/
my @ip_list = qw(;

foreach my $ip (@ip_list)
	my @response = teamasn::get_dns_answer($ip);
	if ( $response[0] == -1 )
		say "There is no info for: ", $ip;
		say "AS: ", $response[0];
		say "NC: ", $response[1];
		say "CC: ", $response[2];
		say "RI: ", $response[3];
		say "DT: ", $response[4];

One can find the ‘teamasn’ source code at:

I will not push ‘teamasn’  to CPAN because it is very premature code and I need extra time to add new features such as:

get_asn: retrieve the AS number only
get_nwc: retrieve the network class only

There are other modules to request AS info such as Net::Whois, however it is HTTP-based and for my needs DNS is better because it is very fast.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.