使い方
curl -s http://ftp.apnic.net/stats/apnic/delegated-apnic-latest | perl jpaddr.pl
#!/usr/bin/perl | |
# | |
# http://ftp.apnic.net/stats/apnic/delegated-apnic-latest | |
# | |
# | |
use strict; | |
use warnings; | |
print "#" x 78 ."\n"; | |
print "# \$Id\$\n"; | |
print "#\n"; | |
print "# http://ftp.apnic.net/stats/apnic/delegated-apnic-latest\n"; | |
print "#\n"; | |
while (my $line = <STDIN>) { | |
next if ($line =~ /^#/); | |
$line =~ s/[\r\n]+$//; | |
my ($registry, $cc, $type, $start, $value, $date, $status) | |
= split(/\|/, $line); | |
if ($registry ne "apnic") { | |
print "#\n"; | |
print "# $line\n" if ($cc eq "apnic"); | |
print "#\n"; | |
print "#" x 78 ."\n"; | |
} | |
next if ($cc ne "JP"); | |
next if ($type ne "ipv4"); | |
printf "%s/%d\n", $start, num2cidr($value); | |
} | |
sub num2cidr { | |
my ($num) = @_; | |
return 32 - log($num)/log(2); | |
} |