Open hege-li opened 4 years ago
Simply writing subdivision_1_iso_code to region seems to fix it. Now IL, Illinois is returned correctly. GeoIP C library code has hardcoded regioncode (IL) to name (Illinois) mapping, also same for timezone record which now works as a result.
--- geolite2legacy.py 2020-05-18 10:02:43.940667166 +0300
+++ geolite2legacy.py 2020-05-18 11:50:21.142837328 +0300
@@ -245,7 +245,10 @@
nets = [ipaddr.IPNetwork(row['network'])]
country_iso_code = location['country_iso_code'] or location['continent_code']
- fips_code = geoname2fips.get(location['geoname_id'])
+ if location['subdivision_1_iso_code'] != "":
+ fips_code = location['subdivision_1_iso_code']
+ else:
+ fips_code = geoname2fips.get(location['geoname_id'])
if fips_code is None:
logging.debug('Missing fips-10-4 for {}'.format(location['subdivision_1_name']))
fips_code = '00'
@hekeli Thanks for the patch! It fixes the problems I was having resolving time zones using the legacy Maxmind API.
I just had the same problem where I noticed that the regions in the test performed correctly for the EU, but not for the USA.
Then I found this topic and thought this would solve the problem. I set up a new version of geolite2legacy that I downloaded from https://github.com/seansweda/geolite2legacy/blob/sean/geolite2legacy.py
Then again the test and the regions for the USA worked correctly. Great.
And when I thought I had solved the problem I found that patched version https://github.com/seansweda/geolite2legacy/blob/sean/geolite2legacy.py fixed the problem with USA regions, but then made a problem with EU regions abd other world region / states, which do not show now any region.
So if I use the sherpya version (which is not patched) then the EU and other world regions are displayed correctly, but not the USA.
If I use the seansweda version (patched) then the USA regions are displayed correctly, but not the EU and other world regions / states.
I don't know if anyone has noticed this problem before? And does anyone have a solution?
Thanks.
To generate IPv4 I use: python geolite2legacy.py -i GeoLite2-City-CSV.zip -o GeoIPCity.dat
I did a patch for just the US given the comments here, seems to work ok:
- fips_code = geoname2fips.get(location['geoname_id'])
+ if country_iso_code == "US" and location['subdivision_1_iso_code'] != "":
+ fips_code = location['subdivision_1_iso_code']
+ else:
+ fips_code = geoname2fips.get(location['geoname_id'])
$ geoiplookup 207.179.201.1
geolite2legacy result: GeoIP City Edition, Rev 1: US, 53, N/A ...
original GeoIP legacy database result: GeoIP City Edition, Rev 1: US, IL, Illinois ...
Atleast US states are ignored completely and not written.
I don't understand what is the purpose of geoname2fips at all? All the country and region data is already found in GeoLite2-City-Locations-en.csv, why isn't it used directly?