#!/usr/bin/perl # script to clean arin generated networks file # apnic|JP|ipv4|202.0.65.0|256|19930101|assigned # wyy@admu.edu.ph use strict; use Net::Patricia; sub log2 { my $n = shift; return log($n)/log(2); } # PLUG in the know PH ipblocks my ($flag,$scanip); my $pt = new Net::Patricia; open (H, $ARGV[0]); while (defined (my $line = )) { chomp ($line); my @a = split (/\s+/, $line); if ($a[0] && $a[1]) { $pt->add_string($a[0], "$a[0] $a[1]"); } } close (H); open (H, $ARGV[1]); my (%astree); while (defined (my $line = )) { chomp ($line); my @a = split (/\s+/, $line); if ($a[0] && $a[1]) { $astree{$a[0]} = $a[1]; } } close (H); while (defined (my $line = )) { chomp ($line); my ($registry, $cc, $resource, $block, $size, $time, $status) = split(/\|/, $line); if (($cc eq "PH") && ($resource eq "asn")) { my ($url, $result, $name, $temp); if ($astree{"AS$block"} eq "") { print "AS"; # $url = "http://www.apnic.net/apnic-bin/whois2.pl?results=all&search=as$block&whois=Go"; # $result = `links -dump "$url" | grep "as-name"`; $result = `fwhois -h whois.apnic.net AS$block | grep "as-name"`; $result =~ s/\s+/ /g; ($temp,$name) = split (/ /, $result); print "$block $name\n"; } } if (($cc eq "PH") && ($resource eq "ipv4")) { my $loop; my $prefix = 32 - log2($size); my $ip = "$block/$prefix"; my ($a, $b, $c, $d) = ($block =~ /^(\d+).(\d+).(\d+).(\d+)/); $flag = 0; for ($loop = 1; $loop <= ($size); $loop++) { $scanip = "$a.$b.$c.$d"; my $found = $pt->match_string($scanip); if (!$found) { $flag = 1; last; } if ($d < 255) { $d++; } else { $d = 0; if ($c < 255) { $c++; } else { $c = 0; if ($b < 255) { $b++; } else { $b = 0; $a++; } } } } if ($flag == 1) { print "$ip ... $scanip "; print "MISSING\n"; } } }