in reply to GeoLite2 get country name from IP
according to the synopsis for GeoIP2::Database::Reader, you can get a country object using:
my $city = $reader->city( ip => '24.24.24.24' ); my $country = $city->country();
then the GeoIP2::Record::Country synopsis shows that you just use the ->name() method on the country object to get the name of the country, like:
print $country->name(), "\n";
(untested, since I don't have GeoLite2)
Notice: in your python code, you first got the city from the reader (first line), then got the country from that, and the name from the country (combined into second line). The perl sequence you presented skipped the city step, and skipped the extraction of the name from the country. The (untested) sequence I present seems to have all three steps that you showed from python.
update: whoops, looking again, there may be an intermediate GeoIP2::Model::Country object, which may require that you instead do
... to extract the GeoIP2::Record::Country from the GeoIP2::Model::Country, and then the name from the record.print $country->country()->name(), "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: GeoLite2 get country name from IP
by Anonymous Monk on Apr 29, 2019 at 14:36 UTC |