Reverse DNS lookup by API: turn an IP into a hostname

A reverse DNS lookup asks for the PTR record of an IP address, stored under a special name: 8.8.8.8 becomes 8.8.8.8.in-addr.arpa with the digits reversed. Any DNS over HTTPS service answers it for free if you build that name yourself, and Python's socket.gethostbyaddr does it through your system resolver. Our DNS Lookup API takes the plain IPv4 or IPv6 address, builds the reverse name and returns the PTR with its TTL for $0.003 per call.

Try it free DNS Lookup API — A, MX, TXT, CAA, SRV, PTR with TTLs, $0.003 · $0.003 / call

How the reverse name is built

Free: DNS over HTTPS by hand

Python's ipaddress module has reverse_pointer built in, so you don't need to reverse digits yourself. socket.gethostbyaddr(ip) is shorter still, but it uses your machine's resolver, blocks, and raises an error when no PTR exists.

import ipaddress, requests

def ptr(ip):
    name = ipaddress.ip_address(ip).reverse_pointer   # builds in-addr.arpa / ip6.arpa
    r = requests.get("https://cloudflare-dns.com/dns-query",
                     params={"name": name, "type": "PTR"},
                     headers={"accept": "application/dns-json"}, timeout=10)
    return [a["data"].rstrip(".") for a in r.json().get("Answer", []) if a["type"] == 12]

print(ptr("8.8.8.8"))          # ['dns.google']
print(ptr("2606:4700:4700::1111"))

The API version

Send the IP as name and our API does the rest: it detects IPv4 or IPv6, builds the reverse name and asks Cloudflare's 1.1.1.1 resolver. The answer includes the response code (NOERROR, NXDOMAIN, SERVFAIL), whether DNSSEC validated, each record with its TTL and, when there's no PTR, the negative TTL. The same endpoint also does forward lookups for A, AAAA, CNAME, MX, NS, TXT, SOA, CAA and SRV, several types per call.

curl -i -X POST https://iamai.markets/api/x402/services/G6O0tWaevy5l \
  -H "Content-Type: application/json" \
  -d '{"name": "1.1.1.1"}'

# An IP with no types defaults to PTR. Price: $0.003 via x402 (USDC on Base).

What reverse DNS can and can't tell you

For a forward-confirmed check, look up the PTR name's A or AAAA record and make sure it points back to the same IP.

UseWorks?
Checking a mail server has a matching PTR (needed by many receivers)Yes
Spotting cloud or hosting IPs by their generic namesOften
Finding every domain hosted on an IPNo. PTR gives one name the IP owner chose, not the sites on it
Proving who sent trafficNo. The IP owner controls the PTR and can write anything

The product

Questions

Is there a free reverse DNS API?

Yes. Cloudflare and Google DNS over HTTPS answer PTR queries free, as long as you send the in-addr.arpa or ip6.arpa name.

Why does my IP have no PTR record?

Reverse records are set by whoever controls the IP block, usually your host or ISP. Many home and cloud IPs have none or a generic one.

Can I mix PTR with other record types in one call?

No. For an IP address only PTR can be looked up; send a domain name for the other nine types.

Related

Updated 2026-12-02