iglov / mmdb-editor

Make your own GeoIP database!
MIT License
10 stars 0 forks source link

Error during Unmarshal(): json: cannot unmarshal object into Go value of type []main.Dataset #27

Closed gustavohellwig closed 2 months ago

gustavohellwig commented 2 months ago

Hi, I'm trying to fix the issue with some IP addresses that don't have some information, like the dataset.json below:

{ "41.59.208.37": { "subdivisions": [ { "iso_code": "TZ", "names": { "en": "Tanzania" } } ], "city": { "names": { "en": "Tanzania" } } } }

That is because Graylog generates errors when those fields are Null.

But when I run mmdb-editor-windows-amd64.exe -i GeoLite2-City.mmdb it generates: Error during Unmarshal(): json: cannot unmarshal object into Go value of type []main.Dataset

What am I doing wrong? Thank you!

iglov commented 2 months ago

Hey there! What version do u use? It's was update upto v2.0.0 and there dataset.json format has been changed. This the correct one:

[
  {
    "networks": ["41.59.208.37/32"],
    "data": {
      "subdivisions": [
        {
          "iso_code": "TZ",
          "names": {
            "en": "Tanzania"
          }
        }
      ],
      "city": {
        "names": {
          "en": "Tanzania"
          }
       }
    }
  }
]

and it works like a charm:

before:

[iglov ~/git/mmdb-editor]$ python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import maxminddb
>>> with maxminddb.open_database('./GeoLite2-City-mod.mmdb') as reader: reader.get('41.59.208.37')
... 
{'continent': {'code': 'AF', 'geoname_id': 6255146, 'names': {'de': 'Afrika', 'en': 'Africa', 'es': 'África', 'fr': 'Afrique', 'ja': 'アフリカ', 'pt-BR': 'África', 'ru': 'Африка', 'zh-CN': '非洲'}}, 'coun
try': {'geoname_id': 149590, 'iso_code': 'TZ', 'names': {'de': 'Tansania', 'en': 'Tanzania', 'es': 'Tanzania', 'fr': 'Tanzanie', 'ja': 'タンザニア連合共和国', 'pt-BR': 'Tanzânia', 'ru': 'Танзания', 'zh-CN
': '坦桑尼亚'}}, 'location': {'accuracy_radius': 1000, 'latitude': -6.8227, 'longitude': 39.2936, 'time_zone': 'Africa/Dar_es_Salaam'}, 'registered_country': {'geoname_id': 149590, 'iso_code': 'TZ', 'name
s': {'de': 'Tansania', 'en': 'Tanzania', 'es': 'Tanzania', 'fr': 'Tanzanie', 'ja': 'タンザニア連合共和国', 'pt-BR': 'Tanzânia', 'ru': 'Танзания', 'zh-CN': '坦桑尼亚'}}}

after:

[iglov ~/git/mmdb-editor]$ ./mmdb-editor 
2024/07/22 21:35:35 Using merge strategy: replace
2024/07/22 21:35:35 Loading mmdb: ./GeoLite2-City.mmdb
2024/07/22 21:37:40 Modifying net: 41.59.208.37/32
2024/07/22 21:37:40 Compiling and writing modified data into: ./GeoLite2-City-mod.mmdb

[iglov ~/git/mmdb-editor]$ python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import maxminddb
>>> with maxminddb.open_database('./GeoLite2-City-mod.mmdb') as reader: reader.get('41.59.208.37')
... 
{'city': {'names': {'en': 'Tanzania'}}, 'subdivisions': [{'iso_code': 'TZ', 'names': {'en': 'Tanzania'}}]}
gustavohellwig commented 2 months ago

Great !!!! Thank you ! Do you know if there is a way to dump all the mmdb to a json, so I can make the changes and recreate the database? thank you again!

iglov commented 2 months ago

Well, there are hundreds of thousands of ranges) If u are talking about official mmdb database, you can just download it in CSV format, change anything u want, and compile with https://github.com/ipinfo/mmdbctl , or just with that mmdbctl u can dump already changed database to CSV or even JSON, but i didn't try 8D

gustavohellwig commented 2 months ago

Thank you so much, your help was very helpful.