Add DNS Lookup and WHOIS to Your AI Agent in Minutes
Published on dev.to — IteraTools series, article #5
If you’re building AI agents that work with the web, sooner or later your agent will need to answer questions like:
- “Who owns this domain?”
- “Is this company’s email properly configured?”
- “When does this competitor’s domain expire?”
- “What IPs does this service resolve to?”
These seem like simple questions — but getting the data programmatically usually means wrestling with raw WHOIS output, installing CLI tools, or juggling multiple libraries. Not ideal when you want your agent to just… work.
This post covers how to add DNS lookup and WHOIS queries to any AI agent using simple REST API calls, with examples in curl and Python.
Why DNS and WHOIS Matter for AI Agents
Network reconnaissance tools aren’t just for security researchers. They’re essential for any agent that deals with businesses, websites, or online services:
- Sales agents checking if a prospect’s domain is about to expire (opportunity!)
- Research agents mapping out a company’s infrastructure
- Email agents verifying MX records before sending campaigns
- Monitoring agents detecting nameserver changes on important domains
- Due diligence agents checking domain registration details during company research
The challenge is integrating these lookups cleanly into an agent workflow. You need structured JSON responses, not raw text parsing — and you need it to be cheap enough to call freely.
DNS Lookup API
The IteraTools DNS Lookup API resolves DNS records for any domain and returns clean JSON. It supports A, AAAA, MX, TXT, CNAME, NS, SOA, and PTR records — up to 8 types in a single request.
Price: $0.001 per request
Endpoint: POST https://api.iteratools.com/dns/lookup
Basic curl example
curl -X POST https://api.iteratools.com/dns/lookup
-H "Authorization: Bearer YOUR_API_KEY"
-H "Content-Type: application/json"
-d '{
"domain": "github.com",
"types": ["A", "MX", "TXT", "NS"]
}'
Response:
{
"success": true,
"domain": "github.com",
"types_queried": ["A", "MX", "TXT", "NS"],
"records": {
"A": ["140.82.121.4"],
"MX": [{ "exchange": "aspmx.l.google.com", "priority": 1 }],
"TXT": ["v=spf1 ip4:192.30.252.0/22 include:_netblocks.google.com ~all"],
"NS": ["ns-421.awsdns-52.com", "ns-520.awsdns-01.net"]
},
"elapsed_ms": 287
}
Python example — DNS agent tool
Here’s how you’d wrap this as a tool for a LangChain or custom agent:
import requests
from typing import Optional
ITERATOOLS_KEY = "your_api_key_here"
BASE_URL = "https://api.iteratools.com"
def dns_lookup(domain: str, types: Optional[list] = None) -> dict:
"""
Look up DNS records for a domain.
Args:
domain: Domain name (e.g. 'example.com'). https:// is stripped automatically.
types: List of record types. Defaults to ['A', 'AAAA', 'MX', 'TXT', 'CNAME', 'NS']
Returns:
Dictionary with records per type.
"""
payload = {"domain": domain}
if types:
payload["types"] = types
response = requests.post(
f"{BASE_URL}/dns/lookup",
headers={"Authorization": f"Bearer {ITERATOOLS_KEY}"},
json=payload,
timeout=15
)
response.raise_for_status()
return response.json()
# Example: Check if a domain has email configured
result = dns_lookup("example.com", ["A", "MX", "TXT"])
records = result["records"]
has_mail = len(records.get("MX", [])) > 0
spf = [r for r in records.get("TXT", []) if r.startswith("v=spf1")]
print(f"Domain resolves to: {records.get('A', [])}")
print(f"Has mail servers: {has_mail}")
print(f"SPF record: {spf[0] if spf else 'Not configured'}")
A practical use case: before your agent sends an email campaign to a list of company domains, it can pre-check which ones have MX records. No MX = no email server = skip that outreach target.
WHOIS Lookup API
While DNS tells you where a domain points now, WHOIS tells you who owns it and when it was registered. The IteraTools WHOIS API wraps WHOIS queries into a clean JSON response.
Price: $0.001 per lookup
Endpoint: POST https://api.iteratools.com/whois
A nice bonus: the API automatically strips https://, paths, and port numbers — so your agent can pass raw URLs without any pre-processing.
Basic curl example
curl -X POST https://api.iteratools.com/whois
-H "Authorization: Bearer YOUR_API_KEY"
-H "Content-Type: application/json"
-d '{"domain": "github.com"}'
Response:
{
"success": true,
"domain": "github.com",
"registrar": "MarkMonitor Inc.",
"creation_date": "2007-10-09T18:20:50Z",
"expiration_date": "2026-10-09T07:00:00Z",
"updated_date": "2023-09-07T09:10:47Z",
"nameservers": [
"ns-421.awsdns-52.com",
"ns-1707.awsdns-21.co.uk"
],
"status": ["clientDeleteProhibited", "clientTransferProhibited", "clientUpdateProhibited"],
"registrant_org": "GitHub, Inc.",
"registrant_country": "US",
"available": false
}
If a domain isn’t registered, available will be true — making it easy to build domain availability checkers.
Python example — domain availability checker
def whois_lookup(domain: str) -> dict:
"""
Get WHOIS data for a domain.
Returns registrar, creation/expiration dates, nameservers, status.
If domain is not registered, returns available=True.
"""
response = requests.post(
f"{BASE_URL}/whois",
headers={"Authorization": f"Bearer {ITERATOOLS_KEY}"},
json={"domain": domain},
timeout=20
)
response.raise_for_status()
return response.json()
# Check domain availability
data = whois_lookup("mynewstartup.com")
if data["available"]:
print("✅ Domain is available!")
else:
print(f"❌ Registered via {data['registrar']}")
print(f" Expires: {data['expiration_date']}")
Combining Both — A Domain Intelligence Agent
Here’s where it gets interesting. Combine DNS + WHOIS into a single “domain intelligence” function that your agent can call to get a comprehensive view of any domain:
import requests
from datetime import datetime, timezone
ITERATOOLS_KEY = "your_api_key_here"
BASE_URL = "https://api.iteratools.com"
def get_headers():
return {"Authorization": f"Bearer {ITERATOOLS_KEY}", "Content-Type": "application/json"}
def dns_lookup(domain, types=None):
payload = {"domain": domain}
if types:
payload["types"] = types
r = requests.post(f"{BASE_URL}/dns/lookup", headers=get_headers(), json=payload, timeout=15)
return r.json() if r.ok else {}
def whois_lookup(domain):
r = requests.post(f"{BASE_URL}/whois", headers=get_headers(), json={"domain": domain}, timeout=20)
return r.json() if r.ok else {}
def domain_intelligence(domain: str) -> dict:
"""
Full domain intelligence report combining DNS + WHOIS.
Returns a structured dict with:
- Registration info (owner, registrar, dates)
- IP addresses
- Mail configuration (MX, SPF)
- Nameservers
- Domain age and days until expiry
"""
# Run both lookups (could be parallelized with asyncio)
dns = dns_lookup(domain, ["A", "AAAA", "MX", "TXT", "NS", "CNAME"])
whois = whois_lookup(domain)
records = dns.get("records", {})
# Calculate domain age and time to expiry
now = datetime.now(timezone.utc)
created = whois.get("creation_date")
expires = whois.get("expiration_date")
domain_age_days = None
days_to_expiry = None
if created:
try:
created_dt = datetime.fromisoformat(created.replace("Z", "+00:00"))
domain_age_days = (now - created_dt).days
except ValueError:
pass
if expires:
try:
expires_dt = datetime.fromisoformat(expires.replace("Z", "+00:00"))
days_to_expiry = (expires_dt - now).days
except ValueError:
pass
# Check email setup
has_mx = len(records.get("MX", [])) > 0
txt_records = records.get("TXT", [])
spf = next((r for r in txt_records if r.startswith("v=spf1")), None)
dkim_hint = any("dkim" in r.lower() for r in txt_records)
return {
"domain": domain,
"available": whois.get("available", False),
"registrar": whois.get("registrar"),
"registrant": whois.get("registrant_org"),
"registrant_country": whois.get("registrant_country"),
"domain_age_days": domain_age_days,
"days_to_expiry": days_to_expiry,
"expiring_soon": days_to_expiry is not None and days_to_expiry < 90,
"ipv4": records.get("A", []),
"ipv6": records.get("AAAA", []),
"nameservers": records.get("NS", whois.get("nameservers", [])),
"mail": {
"has_mx": has_mx,
"mx_records": records.get("MX", []),
"spf": spf,
"has_dkim_hint": dkim_hint,
},
"domain_status": whois.get("status", []),
}
# --- Example usage ---
if __name__ == "__main__":
import json
domains = ["github.com", "stripe.com", "example.com"]
for domain in domains:
print(f"n🔍 Analyzing {domain}...")
intel = domain_intelligence(domain)
print(f" Registrar: {intel['registrar']}")
print(f" Owner: {intel['registrant']} ({intel['registrant_country']})")
print(f" Age: {intel['domain_age_days']} days")
print(f" Expires in: {intel['days_to_expiry']} days",
"⚠️ SOON!" if intel['expiring_soon'] else "")
print(f" IPs: {', '.join(intel['ipv4'])}")
print(f" Mail: {'✅ configured' if intel['mail']['has_mx'] else '❌ no MX'}")
if intel['mail']['spf']:
print(f" SPF: {intel['mail']['spf']}")
Example output:
🔍 Analyzing github.com...
Registrar: MarkMonitor Inc.
Owner: GitHub, Inc. (US)
Age: 6239 days
Expires in: 582 days
IPs: 140.82.121.4
Mail: ✅ configured
SPF: v=spf1 ip4:192.30.252.0/22 include:_netblocks.google.com ~all
Integrating Into an LLM Agent
If you’re using OpenAI function calling or Claude tool use, here’s how to register domain_intelligence as a tool:
tools = [
{
"type": "function",
"function": {
"name": "domain_intelligence",
"description": "Get comprehensive domain intelligence: ownership, registration dates, IP addresses, mail configuration (MX/SPF), and nameservers. Use for research, lead qualification, or infrastructure analysis.",
"parameters": {
"type": "object",
"properties": {
"domain": {
"type": "string",
"description": "Domain name to analyze (e.g. 'example.com'). URLs like https://example.com/path are also accepted."
}
},
"required": ["domain"]
}
}
}
]
Your agent can now answer questions like “Who registered openai.com and when does it expire?” or “Does this company have email properly configured?” with real data.
Getting Started
Both APIs are live at api.iteratools.com:
-
DNS Lookup:
POST /dns/lookup— $0.001/request -
WHOIS:
POST /whois— $0.001/request
Authentication is via Bearer token (pre-paid credits) or x402 micropayments on Base network for pay-as-you-go usage.
Visit iteratools.com to get started. Full API docs at api.iteratools.com/docs.
IteraTools is a collection of microtools built for AI agent developers. $0.001 buys a lot of intelligence.
Tags: ai, agents, dns, whois, api, python, webdev
