Can't get exactly subdivisions iso_code from GeoIP2-City.mmdb with mmdblookup tool
rumato163 opened this issue · 2 comments
When I'm trying to get iso_code of region (subdivision) from GeoIP2-City.mmdb database with mmdblookup if fails with following error:
/usr/share/GeoIP# mmdblookup --file /usr/share/GeoIP/GeoIP2-City.mmdb --ip 8.8.8.8 subdivisions iso_code
Got an error looking up the entry data - The lookup path does not match the data (key that doesn't exist, array index bigger than the array, expected array or map where none exists)
But I can get entire lookup block:
# mmdblookup --file /usr/share/GeoIP/GeoIP2-City.mmdb --ip 8.8.8.8
{
"city":
{
"geoname_id":
5368361 <uint32>
"names":
{
"de":
"Los Angeles" <utf8_string>
"en":
"Los Angeles" <utf8_string>
"es":
"Los Ángeles" <utf8_string>
"fr":
"Los Angeles" <utf8_string>
"ja":
"ロサンゼルス" <utf8_string>
"pt-BR":
"Los Angeles" <utf8_string>
"ru":
"Лос-Анджелес" <utf8_string>
"zh-CN":
"洛杉矶" <utf8_string>
}
}
"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":
"Vereinigte Staaten" <utf8_string>
"en":
"United States" <utf8_string>
"es":
"Estados Unidos" <utf8_string>
"fr":
"États Unis" <utf8_string>
"ja":
"アメリカ" <utf8_string>
"pt-BR":
"EUA" <utf8_string>
"ru":
"США" <utf8_string>
"zh-CN":
"美国" <utf8_string>
}
}
"location":
{
"accuracy_radius":
1000 <uint16>
"latitude":
34.054400 <double>
"longitude":
-118.244100 <double>
"metro_code":
803 <uint16>
"time_zone":
"America/Los_Angeles" <utf8_string>
}
"postal":
{
"code":
"90009" <utf8_string>
}
"registered_country":
{
"geoname_id":
6252001 <uint32>
"iso_code":
"US" <utf8_string>
"names":
{
"de":
"Vereinigte Staaten" <utf8_string>
"en":
"United States" <utf8_string>
"es":
"Estados Unidos" <utf8_string>
"fr":
"États Unis" <utf8_string>
"ja":
"アメリカ" <utf8_string>
"pt-BR":
"EUA" <utf8_string>
"ru":
"США" <utf8_string>
"zh-CN":
"美国" <utf8_string>
}
}
"subdivisions":
[
{
"geoname_id":
5332921 <uint32>
"iso_code":
"CA" <utf8_string>
"names":
{
"de":
"Kalifornien" <utf8_string>
"en":
"California" <utf8_string>
"es":
"California" <utf8_string>
"fr":
"Californie" <utf8_string>
"ja":
"カリフォルニア州" <utf8_string>
"pt-BR":
"Califórnia" <utf8_string>
"ru":
"Калифорния" <utf8_string>
"zh-CN":
"加州" <utf8_string>
}
}
]
}
Looks like the format of the subdivisions part is wrong because of "[" "]" brackets.
subdivisions
is an array there, so something like mmdblookup --file /usr/local/share/GeoIP/GeoIP2-City.mmdb --ip 8.8.8.8 subdivisions 0 iso_code
should work.
That said, you may want to look at mmdbinspect if you are looking to do general MMDB lookups, as the JSON it outputs tends to be easier to work with.
Thanks a lot!
Works perfect.
Frankly JSON output is not the main point. I was trying to get some simple http output with nginx, based on manuals for ngx_http_geoip2_module. And that was the only thing which can't be selected from mmdb.
Looks like number of array's member did the trick!