Javascript – how can we get country name through ip address using jquery

csshtmljavascriptjquery

Please help me to find the country name through ip address using jquery or JavaScript.

I am using this code for getting the ip address. But I am not getting any idea how can we get the country name using the IP Address. Please help me.

<script>
    $.getJSON("http://jsonip.com?callback=?", function (data) {
     alert("Your ip: " + data.ip);
 });
</script>

Please help me

Best Solution

Use a service that actually returns countrynames, like FreeGeoIp

$.getJSON("http://freegeoip.net/json/", function (data) {
    var country = data.country_name;
    var ip = data.ip;
});