This was inspired by one API service from Amazon that simply returns the IP address of the client that's making the request.
mentioned here:
The goal then was to create something that's equally simple to use, but instead to return the country of origin for the connecting IP address which can then be used in many useful ways.
Features:
- No JSON to parse - simple plain text responses.
- No HTTP headers to decode - HTTP 200 everytime.
- No API keys/limits/throttling to deal with - unlimited usage.
- Works with both HTTP and HTTPS.
With this, you get a consistent, plain text response no matter what:
# curl http://country.proxynova.com -i
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Content-Length: 13
United States
In cases where invalid input is provided, an empty response with status code 200 is returned.
curl http://country.proxynova.com
151.101.1.69
Will assume the IP address of the connecting client OR use custom IP provided.
curl http://country.proxynova.com/77.193.88.77
France
Can work with hostnames too:
curl http://country.proxynova.com/vk.com
Russia
$client_ip = $_SERVER['REMOTE_ADDR'];
$country_name = file_get_contents("https://country.proxynova.com/{$client_ip}");
if($country_name == "Pakistan"){
die("Pakistan is Blocked!");
}
https://jsfiddle.net/jf6hqLm9/
$.get("https://country.proxynova.com/", function(data){
if(data == 'Pakistan'){
alert('Pakistan is Blocked!');
}
});
https://jsfiddle.net/bqug7v3x/
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://country.proxynova.com');
xhr.onload = function(){
document.getElementById('country').innerHTML = xhr.responseText;
};
xhr.send();
Some of the country names returned may not be what you expect them to be. For example, Lithuania shows up as "Republic of Lithuania".
To see the exact list of country names used by MaxMind go here:
data/GeoLite2-Country-Locations-en.csv
All the data is from MaxMind.