API Tutorials

DNS Lookup API: How to Check DNS Records Programmatically

Complete developer guide to querying DNS records via API. Working code examples in Python, Node.js, Go, and PHP with caching best practices.

March 17, 202612 min readDeveloper Relations Team
10+
DNS record types
25ms
Average response time
240+
Countries with coverage

What Is a DNS Lookup API?

A DNS lookup API allows developers to programmatically query DNS records for any domain. Instead of manually using command-line tools like dig or nslookup, you can integrate DNS lookups directly into your applications via a simple REST API.

The Ops.Tools DNS Lookup API supports all standard record types including A, AAAA, MX, CNAME, TXT, NS, SOA, PTR, SRV, and CAA records. It returns structured JSON data with record values, TTL information, and metadata.

Supported DNS Record Types

Record TypeDescriptionCommon Use Case
AIPv4 address mappingServer IP resolution
AAAAIPv6 address mappingModern IP resolution
MXMail exchange serversEmail configuration
CNAMECanonical name aliasSubdomain management
TXTText recordsSPF, DKIM, DMARC
NSName serversDNS infrastructure
SOAStart of authorityZone administration
PTRPointer (reverse DNS)Email deliverability

Getting Started

1

Get Your API Key

Sign up for Ops.Tools and generate your API key from the dashboard. Professional plans start at $29/month for 6,000 API calls.

2

Make Your First DNS Lookup

curl -X GET "https://api.ops.tools/v1/dns/lookup" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d "domain=example.com&recordType=A"
3

Parse the JSON Response

{
  "domain": "example.com",
  "recordType": "A",
  "records": [
    {"value": "93.184.216.34", "ttl": 3600}
  ],
  "queryTime": "2026-03-17T10:30:00Z"
}
4

Implement TTL-Based Caching

Use the TTL values from API responses to implement client-side caching. This reduces API calls by 40-60% while ensuring data freshness.

Code Examples

Python

import requests

apiUrl = "https://api.ops.tools/v1/dns/lookup"
headers = {"Authorization": "Bearer YOUR_API_KEY"}

response = requests.get(apiUrl, headers=headers, params={
    "domain": "example.com",
    "recordType": "A"
})
data = response.json()

for record in data["records"]:
    print(f"Value: {record['value']} (TTL: {record['ttl']}s)")

Node.js

const response = await fetch(
  "https://api.ops.tools/v1/dns/lookup?domain=example.com&recordType=MX",
  { headers: { "Authorization": "Bearer YOUR_API_KEY" } }
);
const data = await response.json();

console.log(`Found ${data.records.length} MX records`);
data.records.forEach(r =>
  console.log(`  Priority ${r.priority}: ${r.value} (TTL: ${r.ttl}s)`)
);

Go

req, _ := http.NewRequest("GET",
    "https://api.ops.tools/v1/dns/lookup?domain=example.com&recordType=TXT",
    nil)
req.Header.Set("Authorization", "Bearer YOUR_API_KEY")

client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()

var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Printf("Records: %v\n", result["records"])

PHP

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,
    "https://api.ops.tools/v1/dns/lookup?domain=example.com&recordType=NS"
);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: Bearer YOUR_API_KEY"
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$data = json_decode($response, true);
echo "Name Servers: " . json_encode($data["records"]);

Caching Strategy

Record TypeRecommended CacheReason
A / AAAA1-4 hoursIP changes are infrequent
MX6-12 hoursMail servers rarely change
TXT1-6 hoursSPF/DKIM updates need fast propagation
NS24-48 hoursDNS infrastructure changes are rare

Try the interactive DNS Lookup tool to see a live demonstration. For a deeper understanding of DNS record types, read our complete DNS records guide.

Frequently Asked Questions

Q: What is a DNS lookup API?

A DNS lookup API allows developers to programmatically query DNS records (A, AAAA, MX, CNAME, TXT, NS, SOA, PTR) for any domain. It returns structured JSON data instead of requiring manual DNS tool usage. The Ops.Tools API supports all standard record types with a single endpoint.

Q: How much does a DNS lookup API cost?

Ops.Tools DNS lookup API starts at $29/month for 6,000 lookups. The Growth plan at $99/month includes 32,500 lookups, and the Business plan at $249/month includes 145,000 lookups. Pay-as-you-go credits are also available for variable workloads.

Q: Can I query all DNS record types with one API?

Yes. The Ops.Tools DNS lookup API supports all standard DNS record types including A, AAAA, MX, CNAME, TXT, NS, SOA, PTR, SRV, and CAA records with a single API endpoint. Simply specify the recordType parameter in your request.

Q: What is DNS propagation?

DNS propagation is the process of distributing DNS record changes across all DNS servers worldwide. After making changes, it can take anywhere from a few minutes to 48 hours for all servers to reflect the new records, depending on TTL values. Use the DNS propagation checker to monitor changes globally.

Related Articles

API Tutorials13 min read

IP Geolocation API: Complete Developer Guide

Build location-aware applications with IP geolocation data. Get country, city, ISP, timezone, and VPN detection from any IP address. Code examples included.

Read Article
API Tutorials12 min read

WHOIS Lookup API: Domain Registration Data at Scale

Query WHOIS data programmatically for domain intelligence. Get registrar info, expiration dates, and ownership data. Python, Node.js, Go, and PHP examples.

Read Article
API Tutorials12 min read

API Integration Guide: Getting Started with Ops.Tools APIs

Complete getting started guide for DNS, WHOIS, IP, and SSL APIs. Authentication, code examples, caching strategies, and production deployment patterns.

Read Article

Start Querying DNS Records via API

Get DNS record data for any domain with our reliable API. Plans from $29/month.