elixir-geolix / geolix

IP information lookup provider
Apache License 2.0
190 stars 18 forks source link

City is not being returned in lookup result #12

Closed madshargreave closed 8 years ago

madshargreave commented 8 years ago

Hi

I have downloaded the mmdb database from here

https://dev.maxmind.com/geoip/geoip2/geolite2/

And I use Geolix.set_database(:city, "city.mmdb.gz") \\ :ok to set the path.

However, I get the following results (note how the name field for both country and city is missing)

Geolix.lookup "some ip address"

%{city: %Geolix.Result.City{city: nil,
   continent: %Geolix.Record.Continent{code: "EU", geoname_id: 6324238,
    name: nil,
    names: %{de: "Europa", en: "Europe", es: "Europa", fr: "Europe",
      ja: "ヨーロッパ", "pt-BR": "Europa", ru: "Европа",
      "zh-CN": "欧洲"}},
   country: %Geolix.Record.Country{geoname_id: 26221321, iso_code: "DK",
    name: nil,
    names: %{de: "Dänemark", en: "Denmark", es: "Dinamarca", fr: "Danemark",
      ja: "デンマーク王国", "pt-BR": "Dinamarca", ru: "Дания",
      "zh-CN": "丹麦"}},
   location: %Geolix.Record.Location{latitude: 55.6761, longitude: 12.5683,
    metro_code: nil, time_zone: "Europe/Copenhagen"}, postal: nil,
   registered_country: %Geolix.Record.Country{geoname_id: 2623242,
    iso_code: "DK", name: nil,
    names: %{de: "Dänemark", en: "Denmark", es: "Dinamarca", fr: "Danemark",
      ja: "デンマーク王国", "pt-BR": "Dinamarca", ru: "Дания",
      "zh-CN": "丹麦"}}, represented_country: nil, subdivisions: nil,
   traits: %{ip_address: {some ip...}}}
mneudert commented 8 years ago

Sorry for the confusion regarding the name fields of the results.

Up until now there was no default locale in place if you did not pass one explicitly to Geolix.lookup/2.

If have released version v0.10.1 to hex with a changed and hopefully more intuitive behaviour (should also be more in line with other mmdb2 libraries). With that update you should always get the english result names by default when not passing a locale.

Thank you for bringing this up :+1:

madshargreave commented 8 years ago

Cool, thanks for the quick response

However, the city is still nil

Any ideas?

mneudert commented 8 years ago

Can you share the IP you are looking up?

Just testing various random IPs always gives me a proper result for the city. You might have found an entry that does not have any city data while being in the city database...

madshargreave commented 8 years ago

I am trying with

Geolix.lookup "130.226.239.132"

You're right, I tried with some other ones and I did find a city, but inspecting the CSV database, I do find entries for the city I am in and also nearby cities

mneudert commented 8 years ago

I just did a check with the most current free database and the official python library:

>>> import geoip2.database
>>> city = geoip2.database.Reader('./GeoLite2-City.mmdb')
>>> city.city("130.226.239.132").city
geoip2.records.City(geoname_id=None, confidence=None, _locales=['en'], names={})

RIPE says it is registered to a university. Those IP ranges are sometimes just like company associated ranges just not mapped to any particular city. Paid databases and the official webservice API (check the input on the MaxMind website) may always give better results.

madshargreave commented 8 years ago

Ah I see

I was just looking at http://dev.maxmind.com/geoip/geoip2/javascript/

There's a response with the exact same IP, and it also returns the city and subdivisions. I wasn't aware that data was more limited on the downloaded database, compared to the online webservice

Anyway, thanks for the heads up