DNS Lookup API

The DNS Lookup API retrieves DNS records for any given domain.

/v1/dnslookup

HTTP GET

Returns a list of DNS records associated with a particular domain. Currently the following record types are supported:

  • A

  • AAAA

  • CNAME premium only

  • MX premium only

  • NS

  • PTR

  • SRV

  • SOA

  • TXT premium only

  • CAA

Parameters

domain (required) - valid domain to check (e.g. example.com).

Headers

X-Api-Key (required) - API Key associated with your account.

Sample Request URL

Live Demo!

https://api.api-ninjas.com/v1/dnslookup?domain=

Sample Response

[
  {
    "record_type": "A",
    "value": "93.184.216.34"
  },
  {
    "record_type": "AAAA",
    "value": "2606:2800:220:1:248:1893:25c8:1946"
  },
  {
    "record_type": "MX",
    "priority": 0,
    "value": "."
  },
  {
    "record_type": "NS",
    "value": "b.iana-servers.net."
  },
  {
    "record_type": "NS",
    "value": "a.iana-servers.net."
  },
  {
    "record_type": "SOA",
    "mname": "ns.icann.org.",
    "rname": "noc.dns.icann.org.",
    "serial": 2022040412,
    "refresh": 7200,
    "retry": 3600,
    "expire": 1209600,
    "ttl": 3600
  },
  {
    "record_type": "TXT",
    "value": "wgyf8z8cgvm2qmxpnbnldrcltvk4xqfn"
  },
  {
    "record_type": "TXT",
    "value": "v=spf1 -all"
  }
]

import requests

domain = 'example.com'
api_url = 'https://api.api-ninjas.com/v1/dnslookup?domain={}'.format(domain)
response = requests.get(api_url, headers={'X-Api-Key': 'YOUR_API_KEY'})
if response.status_code == requests.codes.ok:
    print(response.text)
else:
    print("Error:", response.status_code, response.text)
var domain = 'example.com'
$.ajax({
    method: 'GET',
    url: 'https://api.api-ninjas.com/v1/dnslookup?domain=' + domain,
    headers: { 'X-Api-Key': 'YOUR_API_KEY'},
    contentType: 'application/json',
    success: function(result) {
        console.log(result);
    },
    error: function ajaxError(jqXHR) {
        console.error('Error: ', jqXHR.responseText);
    }
});
const request = require('request');
var domain = 'example.com';
request.get({
  url: 'https://api.api-ninjas.com/v1/dnslookup?domain=' + domain,
  headers: {
    'X-Api-Key': 'YOUR_API_KEY'
  },
}, function(error, response, body) {
  if(error) return console.error('Request failed:', error);
  else if(response.statusCode != 200) return console.error('Error:', response.statusCode, body.toString('utf8'));
  else console.log(body)
});
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import com.fasterxml.jackson.databind.ObjectMapper;

URL url = new URL("https://api.api-ninjas.com/v1/dnslookup?domain=example.com");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("accept", "application/json");
InputStream responseStream = connection.getInputStream();
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(responseStream);
System.out.println(root.path("fact").asText());
let domain = "example.com".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
let url = URL(string: "https://api.api-ninjas.com/v1/dnslookup?domain="+domain!)!
var request = URLRequest(url: url)
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "X-Api-Key")
let task = URLSession.shared.dataTask(with: request) {(data, response, error) in
    guard let data = data else { return }
    print(String(data: data, encoding: .utf8)!)
}
task.resume()
If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.