#!/usr/bin/perl if ( -f $ARGV[0] ) { parsefile($ARGV[0]); } else { print"Usage: $0 \n"; } sub have { my ($ip,$cidr) = @_; my $iptok; my @ipparts = split /\./,$ip; $pointer = \%Tree; for( ;$cidr >= 8; $cidr -= 8 ) { $akt = shift @ipparts; $iptok .= "." if ($iptok); $iptok .= $akt; } $Test{"$iptok"} = 1; if ( $cidr > 0 ) { $rest = 8 - $cidr; $base = shift @ipparts; for($i=0 ; $i < 2**$rest;$i++) { $fasel = $base+$i; $Test{"$iptok.$fasel"} = 1; } } } sub known { my ($ip,$cidr) = @_; my @ipparts = split /\./,$ip; my($iptok); while( ($Test{"$iptok"} != 1) && ( $ipparts[0] )) { $akt = shift @ipparts; $iptok .= "." if ($iptok); $iptok .= $akt; } return($Test{"$iptok"}); } sub parsefile{ my ($file) = @_; open( FILE, "< $file") or die "Cant open file $file: $!\n"; open( AS, ">> AS.new") or die "Cant open file $file: $!\n"; open( ROUTEN, ">> routen.new") or die "Cant open file $file: $!\n"; while( ) { my ($route, $desc, $as,$cidr); $_ =~ /^No Match:(.*)$/ || next; $ip = $1; next if( known($ip)); open(NET, "whois -h whois.ra.net $ip |"); while( ) { if ($_ =~ /^route:\s+(.*)\/(\d+)$/) { $route = $1; $cidr = $2}; if ($_ =~ /^origin:\s+AS(\d+)$/) { $as = $1; } } close NET; if( $route ) { printf ROUTEN "%-s/%-2d\t%5d\n",$route,$cidr,$as; have($route,$cidr); if(! $Test2{$as} ) { open(NET, "whois -h whois.ra.net AS$as |"); while( ) { if ($_ =~ /^as-name:\s+(.*)$/) { $asname = $1; } if ($_ =~ /^descr:\s+(.*)$/) { $asdesc = $1; } } $Test2{$as} = 1; printf AS "%-5d\t%s %s\n",$as,$asname,$asdesc; close NET; } } } close FILE; }