DNS Lookup API

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



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

  • A premium only

  • AAAA premium only

  • CNAME premium only

  • MX premium only

  • NS

  • PTR

  • SRV

  • SOA

  • TXT premium only

  • CAA


domain (required) - valid domain to check (e.g. example.com). For top-level domains other than .com, a premium subscription is required.


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

Sample Request URL

Live Demo!


Sample Response

    "record_type": "A",
    "value": ""
    "record_type": "AAAA",
    "value": "2606:2800:21f:cb07:6820:80da:af6b:8b2c"
    "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": 2024041801,
    "refresh": 7200,
    "retry": 3600,
    "expire": 1209600,
    "ttl": 3600
    "record_type": "TXT",
    "value": "v=spf1 -all"
    "record_type": "TXT",
    "value": "wgyf8z8cgvm2qmxpnbnldrcltvk4xqfn"

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("Error:", response.status_code, response.text)
var domain = 'example.com'
    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) {
    error: function ajaxError(jqXHR) {
        console.error('Error: ', jqXHR.responseText);
const request = require('request');
var domain = 'example.com';
  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);
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)!)
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.