I want to extract a user country name from visitors\' IP addresses.
I could get the IP address with remote_ip. But what could be
the easiest way to get
One service you could use to do this is my own, https://ipinfo.io. It gives you country code and a bunch of other details:
$ curl ipinfo.io
{
"ip": "24.6.61.239",
"hostname": "c-24-6-61-239.hsd1.ca.comcast.net",
"city": "Mountain View",
"region": "California",
"country": "US",
"loc": "37.3845,-122.0881",
"org": "AS7922 Comcast Cable Communications, LLC",
"postal": "94040"
}
If you just want the country you can get that by requesting /country
$ curl ipinfo.io/country
US
You can then map from a country code to a name using the data from http://country.io, or using the example at http://ipinfo.io/developers/full-country-names