0

i want to get the country name by give IPAdress in java. e.g 192.168.0.1 . i want to get country name not host name. please solve this issue.

Lloyd
  • 29,197
  • 4
  • 84
  • 98
user1175106
  • 89
  • 2
  • 9
  • 2
    [What have you tried?](http://www.whathaveyoutried.com/) Also, Java =/= JavaScript. Removing the JS tag. – Cerbrus Feb 14 '13 at 11:31
  • 2
    There are plenty of examples on how to use things like MaxMind GeoIP Country out there. Also 192.168.0.0/16 is a private address block and won't resolve to a country. – Lloyd Feb 14 '13 at 11:31
  • please past the link here. – user1175106 Feb 14 '13 at 11:32
  • 1
    http://dev.maxmind.com/geoip/geolite – Lloyd Feb 14 '13 at 11:33
  • You can refer to following two SO Questions: http://stackoverflow.com/questions/2257170/how-to-get-city-name-based-on-ip-address-in-java http://stackoverflow.com/questions/1374178/ip-to-country-city-lat-lang-javascript-service – Azodious Feb 14 '13 at 11:35
  • Try this:http://www.lazylab.org/40/java/resolve-ip-to-country-name-in-java/ – Alya'a Gamal Feb 14 '13 at 11:35

1 Answers1

5

There are many geolocation providers such as this free one:

http://freegeoip.net/static/index.html

This one allows up to 1000 lookups per hour for free.

If you access for example: http://freegeoip.net/json/124.168.50.23 to look up the address, you will find out that I'm in Australia:

{"city": "Sydney", "region_code": "02", "region_name": "New South Wales", "areacode": "", "ip": "124.168.50.23", "zipcode": "", "longitude": 151.2055, "country_name": "Australia", "country_code": "AU", "metrocode": "", "latitude": -33.8615}

Note that the example IP address you used (192.168.0.1) is from a reserved range (it's always on your local network), so you can't look up a country for it:

{"city": "", "region_code": "", "region_name": "", "areacode": "", "ip": "192.168.0.1", "zipcode": "", "longitude": "", "country_name": "Reserved", "country_code": "RD", "metrocode": "", "latitude": ""}

Tobias
  • 1,107
  • 7
  • 8