I knocked this out this afternoon after someone mentioned that the asn.txt file from ARIN
didn't have descriptions of the ASes.
This script takes the asn.txt file from arin.net, pulls the AS number, and does a whois call
to radb.net to see what the owner has put in for a description.
Its very raw but it produces some halfway useable output. If anyone cares enough to send
suggestions I'll consider them and add them. Who knows, might even get ambitious and write a
.pm and submit it to cpan.org.
#!/usr/bin/perl
# we're only gonna make one teeny, weeny socket call
use IO::Socket ;
#be sure to have asn.txt in the directory where you invoke this program
open(fhand,"asn.txt") ;
while(<fhand>)
{
# trim the trailing line feed out of habit
chomp ;
# simple regex to pull the first string of digits found on each line
# yes, this doesn't handle things like this but its pretty close
# 199-203 BARRNET-BLK [BNOC-ARIN]
/ *(\d*)/ ;
# put the results from the regex in a variable so we don't frighten any
pascal
# programmers who are looking at this code
$as = $1 ;
#open the socket to the whois server
$sock = new IO::Socket::INET("whois.radb.net:43") || die $! ;
# send our request
print $sock "AS$as\n" ;
#get all of the output
@lines = <$sock> ;
# now we look at the lines for a description
foreach (@lines)
{
chomp ;
if(/descr/)
{
$descr = $_ ;
}
}
#we store the results in an associative array indexed by AS number
$asdesc{$as} = $descr ;
# now we print a single line with the AS number and description
print "AS$as" . substr(" ",0,5-length($as)) . " " . $descr . "\n" ;
# and we'll empty the description because some of the ASes don't have them
$descr = "" ;
}
#ok, now we've got our description and numbers in an associative array
#and we're ready to do other fun stuff with it.
-- cflowd mailing list cflowd@caida.org
This archive was generated by hypermail 2b29 : Tue Oct 17 2000 - 14:07:37 PDT