mmdbctl icon indicating copy to clipboard operation
mmdbctl copied to clipboard

is ipapi csv's conversion supported?

Open jkuj6 opened this issue 2 years ago • 6 comments

i want to use the csv DB file from https://ipapi.is/developers.html#geolocation-database but when i try to convert it with: mmdbctl import --in geolocationDatabaseIPv4.csv --out data.mmdb i get error: err: couldn't parse cidr "4/32": invalid CIDR address: 4/32

Why is it giving this error? Is it possible you can see if you can make this conversion for ipapi csv's compatible with mmdbctl?

thanks in advance

ps: surprised no-one has mentioned ipapi.is db's

jkuj6 avatar Feb 19 '24 10:02 jkuj6

Hi, I took a look at the database and it seems that the CSV database is not consistent.

mmdbctl import --in data.csv --out data.mmdb

Output

warn: couldn't insert line '154.17.129.024,154.17.129.024,EU,PL,Poland,Mazovia,Warsaw,05-077,Europe/Warsaw,52.22977,21.01178,1'
warn: couldn't insert line '185.208.9.024,185.208.9.024,EU,FR,France,Île-de-France,Paris,75998 CEDEX 14,Europe/Paris,48.85341,2.3488,1'
warn: couldn't insert line '60.54.50.0,0.0.0.0,AS,MY,Malaysia,Selangor,Putra Heights,47130,Asia/Kuala_Lumpur,2.9679,101.653,1'
warn: couldn't insert line '60.54.51.0,0.0.0.0,AS,MY,Malaysia,Selangor,Putra Heights,47130,Asia/Kuala_Lumpur,2.9679,101.653,1'

Please note the following:

185.208.9.024

The 024 contains the starting digit of 0, which results in the mmdbctl database declaring it to be an invalid IP address. This should be 185.208.9.24.

IPapi.is recognizes IP address to be valid: https://api.ipapi.is/?q=185.208.9.024

But IPinfo does not: https://ipinfo.io/185.208.9.024/json

60.54.51.0,0.0.0.0

This is not a valid IP range as the end_ip value precedes the start_ip value.

If the IP database can return consistent and valid rows, there should be no problem using mmdbctl to convert the CSV dataset to the MMDB dataset.

In the meanwhile, feel free to check out IPinfo's free IP database: https://ipinfo.io/products/free-ip-database

Let me know what you think. Thanks!

abdullahdevrel avatar Feb 26 '24 21:02 abdullahdevrel

@jkuj6

I noticed that you are trying to set up NGINX with a geolocation database. You can check out IPinfo's free IP to Country database for that. Here are the instructions: https://ipinfo.io/blog/nginx-for-access-control-and-privacy-policies/

abdullahdevrel avatar Mar 02 '24 17:03 abdullahdevrel

Fixed in commit https://github.com/ipapi-is/ipapi/commit/ec751295c80e502ae8b67cba7f6b7d53e9a71346 You should be able to convert it now.

ipapi-is avatar Mar 07 '24 18:03 ipapi-is

How does my CSV file need to be structured in order to read it into MMDB format?

mmdbctl import --in geolocationDatabaseIPv4.csv --out data.mmdb

fails with

err: couldn't parse cidr "4/32": invalid CIDR address: 4/32

My file does not contain CIDR ranges. That's a strange error.

My file looks like this:

ip_version,start_ip,end_ip,continent,country_code,country,state,city,zip,timezone,latitude,longitude,accuracy
4,5.189.37.0,5.189.37.255,EU,RU,Russia,Свердловская Область,Yekaterinburg,901079,Asia/Yekaterinburg,56.8519,60.6122,2
4,185.67.40.0,185.67.40.255,EU,NO,Norway,Nordland,Bodø,8108,Europe/Oslo,67.2981512081068,14.399771690368652,2
4,185.46.121.0,185.46.121.255,NA,US,United States,Noord-Holland,Amsterdam,1109,Europe/Amsterdam,52.36889170602552,4.8944091796875,2
4,185.46.122.0,185.46.122.255,NA,US,United States,Noord-Holland,Amsterdam,1109,Europe/Amsterdam,52.36889170602552,4.8944091796875,2
4,185.46.123.0,185.46.123.255,NA,US,United States,Noord-Holland,Amsterdam,1109,Europe/Amsterdam,52.36889170602552,4.8944091796875,2

ipapi-is avatar Mar 07 '24 18:03 ipapi-is

Hi,

The mmdbctl tool accepts files in a CSV format that begin with start_ip and end_ip columns. The first column of the IPapi.is IP database is ip. If you remove that column and try again, it will work. Can you please check? Thanks.

abdullahdevrel avatar Mar 07 '24 18:03 abdullahdevrel

Remove first column from the database:

cut -d, -f2- geolocationDatabaseIPv4.csv > data.csv

Then convert:

mmdbctl import --in data.csv --out data.mmdb

that works like a charm and yields:

writing to data.mmdb (1347178 entries)

ipapi-is avatar Mar 07 '24 19:03 ipapi-is

Looks like the issue has been resolved. Feel free to reopen if the problem persists. Thank you.

abdullahdevrel avatar Jul 30 '24 14:07 abdullahdevrel