appliedsec/pygeoip — Issue #2: GeoIPRegion.dat queries don't work for outside US and Canada
Author: jennifere
Created: 2012-01-13 13:37:42+00:00
State: open

What steps will reproduce the problem?
1. Grab GeoIPRegion.dat from Maxgrind
2. country1 = country_code_by_name('france2.fr')
3. country2 = country_code_by_addr('212.23.176.132')

What is the expected output? What do you see instead?
country1 and country2 should both be 'FR'. It returns empty.

What version of the product are you using? On what operating system?
Using pygeoip 0.2.2, reproduced on windows and linux platforms.

Please provide any additional information below.
This is working if I'm using the official python package from maxgrind. Another IP address in India (122.174.46.61) is also never resolved. Working with GeoLiteCity.
IP from Canada or US seem to be resolved correctly.

Delete comment Comment 1 by nahor.j, Nov 4, 2011
I believe the issue is in _get_region:
if i in const.COUNTRY_CODES

I assume that this code is supposed to verify that i is inside the array boundary limits. But what it really does is test if i is a value in the array, which is always false.

And while I'm at it, there is this code in a couple of places in the same function:
(seek_region // 1000) // 26
which I think should be:
(seek_region - 1000) // 26
Delete comment