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.
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 Type | Description | Common Use Case |
|---|---|---|
| A | IPv4 address mapping | Server IP resolution |
| AAAA | IPv6 address mapping | Modern IP resolution |
| MX | Mail exchange servers | Email configuration |
| CNAME | Canonical name alias | Subdomain management |
| TXT | Text records | SPF, DKIM, DMARC |
| NS | Name servers | DNS infrastructure |
| SOA | Start of authority | Zone administration |
| PTR | Pointer (reverse DNS) | Email deliverability |
Getting Started
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.
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"
Parse the JSON Response
{
"domain": "example.com",
"recordType": "A",
"records": [
{"value": "93.184.216.34", "ttl": 3600}
],
"queryTime": "2026-03-17T10:30:00Z"
}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 Type | Recommended Cache | Reason |
|---|---|---|
| A / AAAA | 1-4 hours | IP changes are infrequent |
| MX | 6-12 hours | Mail servers rarely change |
| TXT | 1-6 hours | SPF/DKIM updates need fast propagation |
| NS | 24-48 hours | DNS 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
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 ArticleWHOIS 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 ArticleAPI 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 ArticleStart Querying DNS Records via API
Get DNS record data for any domain with our reliable API. Plans from $29/month.