2013-03-17 05:11:43 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
#aslookup.pl - Looks up information on a given ASN or IP address
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Net::Whois::RIPE;
|
|
|
|
|
|
|
|
my $default_as_server = "whois.radb.net";
|
|
|
|
my %whois_options = (
|
|
|
|
"hostname" => $default_as_server,
|
|
|
|
);
|
|
|
|
|
2013-03-17 05:39:51 +00:00
|
|
|
if($#ARGV < 0 || $ARGV[0] eq "") {
|
|
|
|
print "Provide an IP or ASN to look up";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
my $target = $ARGV[0];
|
2013-03-17 05:11:43 +00:00
|
|
|
my $whois = Net::Whois::RIPE->new(%whois_options);
|
2013-03-17 05:37:32 +00:00
|
|
|
my $witerator = $whois->query($target);
|
|
|
|
while($witerator->isnt_exhausted) {
|
|
|
|
my ($asnum,$asname,$descr,$origin,$route);
|
|
|
|
my @whoisdata = split /\n/, $witerator->value();
|
|
|
|
foreach (@whoisdata) {
|
|
|
|
$asnum = $_ if /^aut-num:/;
|
|
|
|
$asname = $_ if /^as-name:/;
|
|
|
|
$descr = $_ if /^descr:/;
|
|
|
|
$origin = $_ if /^origin:/;
|
|
|
|
$route = $_ if /^route:/;
|
|
|
|
}
|
2013-03-17 05:42:24 +00:00
|
|
|
$descr =~ s/.*:[ ]+//;
|
2013-03-17 05:37:32 +00:00
|
|
|
if($target =~ /^AS.*/i) {
|
|
|
|
$asnum =~ s/.*:[ ]+//;
|
|
|
|
$asname =~ s/.*:[ ]+//;
|
2013-03-17 05:43:52 +00:00
|
|
|
print "$target is $descr ($asname)\n";
|
2013-03-17 05:37:32 +00:00
|
|
|
} else {
|
|
|
|
$origin =~ s/.*:[ ]+//;
|
|
|
|
$route =~ s/.*:[ ]+//;
|
|
|
|
print "$route advertised by $origin - $descr\n";
|
|
|
|
}
|
2013-03-17 05:11:43 +00:00
|
|
|
}
|