City returns empty for GeoLite2 database
Opened this issue · 1 comments
I'm getting no City value when I lookup anything. I do get Country information though. Is this just not provided in the Lite database?
[TestClass]
public class DatabaseReaderTests
{
private DatabaseReader reader;
[TestInitialize]
public void Setup()
{
this.reader = new DatabaseReader("GeoLite2-City.mmdb", new[] { "en" }, FileAccessMode.Memory);
}
[DataTestMethod]
[DataRow("213.171.195.48", "GB", "Gloucester")]
[DataRow("31.13.65.36", "IE", "Dublin")]
[DataRow("217.160.86.40", "DE", "Karlsruhe")]
[DataRow("64.233.162.100", "US", "Mountain View")]
[DataRow("13.77.161.179", "US", "Quincy")]
public void City_IpAddressReturnsExpectedCountryAndCIty(string ipAddress, string expectedCountryCode, string expectedCity)
{
CityResponse city = this.reader.City(ipAddress);
Assert.IsNotNull(city);
Assert.AreEqual(expectedCountryCode, city.Country.IsoCode);
Assert.AreEqual(expectedCity, city.City.Name);
}
}
Hi, the issue is that you are looking up IPs in the database for which we don't have a city record - the data is just not there.
If you look up the data using a tool such as mmdblookup
, found here, you'll see that none of the IPs you posted have a "city"
field. E.g.:
$ mmdblookup --file /usr/share/GeoIP/GeoLite2-City.mmdb --ip 13.77.161.179
{
"continent":
{
"code":
"NA" <utf8_string>
"geoname_id":
6255149 <uint32>
"names":
{
"de":
"Nordamerika" <utf8_string>
"en":
"North America" <utf8_string>
"es":
"Norteamérica" <utf8_string>
"fr":
"Amérique du Nord" <utf8_string>
"ja":
"北アメリカ" <utf8_string>
"pt-BR":
"América do Norte" <utf8_string>
"ru":
"Северная Америка" <utf8_string>
"zh-CN":
"北美洲" <utf8_string>
}
}
"country":
{
"geoname_id":
6252001 <uint32>
"iso_code":
"US" <utf8_string>
"names":
{
"de":
"USA" <utf8_string>
"en":
"United States" <utf8_string>
"es":
"Estados Unidos" <utf8_string>
"fr":
"États-Unis" <utf8_string>
"ja":
"アメリカ合衆国" <utf8_string>
"pt-BR":
"Estados Unidos" <utf8_string>
"ru":
"США" <utf8_string>
"zh-CN":
"美国" <utf8_string>
}
}
"location":
{
"accuracy_radius":
1000 <uint16>
"latitude":
47.609200 <double>
"longitude":
-122.331400 <double>
"time_zone":
"America/Los_Angeles" <utf8_string>
}
"registered_country":
{
"geoname_id":
6252001 <uint32>
"iso_code":
"US" <utf8_string>
"names":
{
"de":
"USA" <utf8_string>
"en":
"United States" <utf8_string>
"es":
"Estados Unidos" <utf8_string>
"fr":
"États-Unis" <utf8_string>
"ja":
"アメリカ合衆国" <utf8_string>
"pt-BR":
"Estados Unidos" <utf8_string>
"ru":
"США" <utf8_string>
"zh-CN":
"美国" <utf8_string>
}
}
"subdivisions":
[
{
"geoname_id":
5815135 <uint32>
"iso_code":
"WA" <utf8_string>
"names":
{
"en":
"Washington" <utf8_string>
"es":
"Washington" <utf8_string>
"fr":
"Washington" <utf8_string>
"ja":
"ワシントン州" <utf8_string>
"ru":
"Вашингтон" <utf8_string>
"zh-CN":
"华盛顿州" <utf8_string>
}
}
]
}
However, if you look up an IP that does have data in the database, you'll see the "city"
field:
$ mmdblookup --file /usr/share/GeoIP/GeoLite2-City.mmdb --ip 173.213.100.106
{
"city":
{
"geoname_id":
5506956 <uint32>
"names":
{
"de":
"Las Vegas" <utf8_string>
"en":
"Las Vegas" <utf8_string>
"es":
"Las Vegas" <utf8_string>
"fr":
"Las Vegas" <utf8_string>
"ja":
"ラスベガス" <utf8_string>
"pt-BR":
"Las Vegas" <utf8_string>
"ru":
"Лас-Вегас" <utf8_string>
"zh-CN":
"拉斯维加斯" <utf8_string>
}
}
[...snip...]
Moreover, I would strongly recommend against using a production database in your tests, because the underlying data in the database changes from release to release. Instead, you could test using a test DB, found here. You could store a version of the file in your repo and the data would never change.
Hope this helps.