#!/usr/bin/perl use GeoIP2::Database::Reader; # GeoLite2-City.mmdb if ( $ARGV[0] eq '-h' || $ARGV[0] eq '-help' || $ARGV[0] eq '' ) { help(); exit; } my $reader = GeoIP2::Database::Reader->new( file => '/usr/share/GeoIP/GeoLite2-City.mmdb', locales => [ 'en', 'de', ] ); my $city = $reader->city( ip => $ARGV[0] ); my $city_rec = $city->city(); print "City: ", $city_rec->name(), "\n"; my $country = $city->country(); print "Country: ", $country->iso_code(), "\n"; sub help { print "Usage: ./geoipcity.pl 1.2.3.4\n"; }