DNS

An API for retrieving the Client Subnet in DNS Requests (edns-client-subnet).

Usage

To receive the response in JSON format, send a GET request to

http://[32 random alphanumeric characters].edns.ip-api.com/json

or, for automatic redirection (slower)

http://edns.ip-api.com/json

from the client's browser. Sending this request from your own server will return the DNS info for that server, which is probably not useful.

Response

A successful request will return the following (example):

{
    "dns": {
        "ip": "74.125.73.83",
        "geo": "United States - Google"
    },
    "edns": {
        "ip": "91.198.174.0",
        "geo": "Netherlands - Wikimedia Foundation"
    }
}

dns contains the IP address and Geolocation (country, ISP) of the DNS server the client used.
edns contains the IP address and Geolocation (country, ISP) of the client. If the DNS server did not send the client subnet, the edns field will be be absent.

Results are cached for 60 seconds from the time of the DNS query. If the requested result (domain) expired, the user will be redirected to a new, randomly generated domain.

We are whitelisted for edns-client-subnet with Google Public DNS and OpenDNS.

Test via Google Public DNS:
API_HOST=$(</dev/urandom tr -dc a-z0-9|head -c32).edns.ip-api.com; API_IP=$(dig $API_HOST +short @8.8.8.8); curl -H "Host: $API_HOST" http://$API_IP/json
Test via OpenDNS:
API_HOST=$(</dev/urandom tr -dc a-z0-9|head -c32).edns.ip-api.com; API_IP=$(dig $API_HOST +short @208.67.222.222); curl -H "Host: $API_HOST" http://$API_IP/json

Callback (JSONP)

By default there is no callback function called, but you can supply your own with the GET parameter callback

Callback Example

HTML and jQuery Example

JS Bin

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
        <title>IP-API.com EDNS Demo</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    </head>
    <body>
        <pre id="results"></pre>
        <script>
	    var randomStr="";
	    var chars="abcdefghijklmnopqrstuvwxyz0123456789";
	    for(var a=0;a<32;a++) {
	    	randomStr += chars.charAt(Math.floor(Math.random()*chars.length));
	    }
	    $.getJSON("http://" + randomStr + ".edns.ip-api.com/json?callback=?", function(data) {
	    	debug = JSON.stringify(data, undefined, 2);
	    	$("#results").html(debug);
	    });
        </script>
    </body>
</html>