How to get the user's country for a HTTP request in the Backend?

Viewed 2627

I am trying to get the country where the user is sending the request to my server.

So far I have found those solutions:

https://github.com/fiorix/freegeoip

https://github.com/maxmind/GeoIP2-java

These solutions are using MaxMind database GeoIP2 Country Database which has a license and for this specific project I have restriction with Libraries (legal aspects because of the business)

I have found some topics mentioning that Google API can provide this service, but that doesn't interest me as I want a solution that I can host myself and it is implemented using Java or Kotlin.

Does someone know a solution different from the one mentioned (that runs on the backend)?

2 Answers

I've coded a little service that returns the country based on data I've acquired from http://ipverse.net/

It should be license free but correct me if I am wrong. According to the website the data is provided by the five big RIRs.

The website updates its data ~5am. The Cron job that updates the IP Blocks is scheduled at 6am. The data should be accurate I guess.

*edit I've replicated the algo and created a github action to keep it updated, check it out: https://github.com/jaecktec/ncc-inetnum-parser

Related