On Wed, 12 Apr 2017 14:15:09 +0900, Norbert Preining wrote: > it seems there is an incompatibility between the geoip-database shipped in > Debian and the module Geo::IP. > > Trying to do (according to the docs): > use Geo::IP; > my $gi = Geo::IP->new(GEOIP_MEMORY_CACHE); > my $record = $gi->record_by_addr($ip); > results in: > Invalid database type GeoIP Country Edition, expected GeoIP City > Edition, Rev 1 > > Same with > my $gi = Geo::IP->open( '/usr/share/GeoIP/GeoIP.dat', > GEOIP_MEMORY_CACHE );
I haven't tried it yet but my impression is that the record_by_addr() method wants a city database: Code: *record_by_addr = \&get_city_record_as_hash; POD: use Geo::IP; my $gi = Geo::IP->open("/usr/local/share/GeoIP/GeoIPCity.dat", GEOIP_STANDARD); my $record = $gi->record_by_addr('24.24.24.24'); i.e. city data (GeoIPCity.dat) while the geoip-database package only ships the country database (GeoIP.dat). This means that all functions that use the country .dat should work, and for the city-needing functions one would either need to get the file from https://dev.maxmind.com/geoip/legacy/geolite/ or convince the geoip-database maintainers to ship it (or them: ipv4 + ipv6) in the package a well. Ok, now let's try: Taking the other example from the POD: #v+ #!/usr/bin/perl use strict; use warnings; use Geo::IP; my $gi = Geo::IP->new(GEOIP_MEMORY_CACHE); my $country = $gi->country_code_by_addr('24.24.24.24'); print "$country\n"; $country = $gi->country_code_by_name('yahoo.com'); print "$country\n"; #v- % perl geoip.pl US US Works as expected. And with http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz and the other example from the POD which matches your second example: #v+ #!/usr/bin/perl use strict; use warnings; use Geo::IP; my $gi = Geo::IP->open( '/home/gregoa/tmp/GeoLiteCity.dat', GEOIP_STANDARD ); my $record = $gi->record_by_addr('24.24.24.24'); print $record->country_code, $record->country_code3, $record->country_name, $record->region, $record->region_name, $record->city, $record->postal_code, $record->latitude, $record->longitude, $record->time_zone, $record->area_code, $record->continent_code, $record->metro_code; #v- % perl geoip.pl USUSAUnited StatesNYNew YorkSyracuse1320143.0481-76.1474America/New_York315NA555 (Ok, some linebreaks would be nice). Good. So my conclusions are: - Geo::IP works with the geoip-database data as long as only the the country data are used; - for functions which need the city data they have to be downloaded manually or should be shipped in geoip-database; - I think this is, if any, not an RC bug in libgeo-ip-perl; and/or - maybe a bug in geoip-database? Or just the way it is when working with external data ... Cheers, gregor -- .''`. https://info.comodo.priv.at/ - Debian Developer https://www.debian.org : :' : OpenPGP fingerprint D1E1 316E 93A7 60A8 104D 85FA BB3A 6801 8649 AA06 `. `' Member of VIBE!AT & SPI, fellow of the Free Software Foundation Europe `- NP: Van Morrison
signature.asc
Description: Digital Signature