#!/usr/bin/perl
#Quickly written by Deltaray with the help from kind people on the #perl channel.
use Tie::NetAddr::IP;
my %netblocks;
tie %netblocks, Tie::NetAddr::IP;
$blocklist = '/home/mkrenz/netblocks2/biglist';
open(BLOCKLIST, $blocklist) || die();
# Assumes '<block> <country>' format to the file.
while (<BLOCKLIST>) {
chomp($_);
$line = $_;
next if ($line =~ m/^#/);
($block, $country) = split(/\s+/, $line);
$netblocks{$block} = $country;
}
close(BLOCKLIST);
print "Ready\n";
while (<STDIN>) {
chomp($_);
$ip = $_;
$return = $netblocks{$ip};
if ($return) {
print "$return\n";
} else {
print "UNKNOWN\n";
}
}
untie %netblocks;