#!/usr/bin/perl -w
#
# ::copy::
# ::maintainer::
#
use Geo::IP;

my $gi = Geo::IP->new(GEOIP_STANDARD);
my $country;
my $name;

if (scalar(@ARGV) != 1) {
	usage();
}

if ($ARGV[0] =~ /^[0-9]/) {
	$country = $gi->country_code_by_addr( $ARGV[0] );
	$name = $gi->country_name_by_addr( $ARGV[0] );
} else {
	$country = $gi->country_code_by_name( $ARGV[0] );
	$name = $gi->country_name_by_name( $ARGV[0] );
}

if (defined $country) {
	printf( "%s;%s;%s\n", $ARGV[0], $country, $name );
	exit( 0 );
}

exit( 1 );



sub usage
{
	die "
usage: geoip ip_or_hostname

returns:
  ip_or_hostname;country;country_name
\n";
}
