Geolocation IP in Java [closed]

依然范特西╮ 提交于 2019-12-02 20:44:20

问题


Is there any way to get the country, city (generally: geolocation information) from IP address. Note that my application is java.

I visisted and tried many web services, but I didn't find suitable one and I prefer to write my own. Also, I found some CSV DBs but also this solution is not preferable at all. please, help.


回答1:


All you need is GeoIP, provided by MaxMind company.

They provide free GeoIP2 database - GeoLite2 and several GeoIP2 APIs(thanks karel) including Java API to read database file too.

  • Documents
  • Java API
  • Downloadable Java libraries
  • Downloadable Java libraries from maven.org, my favorite :), you need download both com.maxmind.db and com.maxmind.geoip2.

Before GeoIP2, there was GeoIP, now they called it GeoIP Lecacy, Free databases and downloadable Java library from maven.org or from github are still available.

GeoIP Lecacy maybe dead in the future, however, for now, because GeoIP2 doesn't provide Java API to read the database information (such as GEO-533LITE 20150303 Build 1 Copyright (c) 2015 MaxMind Inc All Rights Reserved), so I still use it in my website. I use GeoIP2 in my IRC bot to benefit from the multiple language feature of GeoIP2.




回答2:


Each country has a few range of IPs.

I'm not aware of a Java implementation of that, but you could use the output from http://services.ce3c.be/ciprg/ and create your own code that gives the country based upon the IP address.



来源:https://stackoverflow.com/questions/11138071/geolocation-ip-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!