ASN file utility in perl

From: Neal Rauhauser (
Date: Tue Oct 17 2000 - 08:54:59 PDT

  • Next message: Mark Manuel C. Ramos: "cflowd dies"

       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, pulls the AS number, and does a whois call
    to 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

    # 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") ;
                    # 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
                    # programmers who are looking at this code
                    $as = $1 ;

                    #open the socket to the whois server
                    $sock = new IO::Socket::INET("") || 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 ;
                                                    $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

    This archive was generated by hypermail 2b29 : Tue Oct 17 2000 - 14:07:37 PDT