Disclosure: I built the Apify Actor mentioned near the end of this post.
To check if a domain is still active, ask DNS for its A record and read the response code, not just "did I get an IP": NXDOMAIN means the name does not exist in DNS, NOERROR with no answer (NODATA) means it exists but has no address, and SERVFAIL means its DNS is broken. None of these tells you whether the domain is registered; for that, ask RDAP, the registries' free JSON replacement for WHOIS. A domain can be registered and not resolve, and a domain can resolve and still have no working website, so a useful check reports these as separate states.
This post walks through a standard-library Python script that sorts a list of domains into those states, then shows a hosted option at the end.
Why is "it resolves" not the same as "it is active"?
The common one-liner is socket.gethostbyname(domain) in a try/except. It answers one question (did I get an IPv4 address from my resolver?) and folds every failure into one gaierror. For a list of domains you usually want to know why a domain failed, because the follow-up is different:
| What you see | What it means | What to do next |
|---|---|---|
NXDOMAIN | The name does not exist in DNS | Check RDAP: expired, on hold, or never registered? |
NOERROR, no A/AAAA (NODATA) | The domain exists (it has name servers) but no address | Often a mail-only or parked domain; not dead |
SERVFAIL | The resolver could not get a valid answer (dead name servers, broken DNSSEC) | Domain is probably registered, its DNS is broken |
Address is 127.0.0.1, 10.x, ::1 | Resolves, but not to anything reachable from the internet | Treat as not live |
| Public IP, HTTPS fails | DNS is fine, the website is not | Certificate, server or firewall problem |
DNS response codes are defined in RFC 1035 (section 4.1.1), and "NODATA" is described in RFC 2308 as a NOERROR answer with an empty answer section.
How do I get the DNS status code from Python?
socket does not expose it, so I use Cloudflare's free DNS-over-HTTPS JSON endpoint, which returns the code as a number in Status (0 = NOERROR, 2 = SERVFAIL, 3 = NXDOMAIN). It needs only the header Accept: application/dns-json. If you prefer your own resolver, dnspython raises NXDOMAIN and NoAnswer as separate exceptions and the logic below is the same.
How do I check if a domain is registered without scraping WHOIS?
Use RDAP (RFC 9083). Registries publish it as JSON over HTTPS, and rdap.org redirects you to the right registry server for each TLD. On 2026-12-01, https://rdap.org/domain/dnssec-failed.org answered with a 302 to the .org registry's RDAP server, and a made-up .com name went to Verisign's server and came back 404.
-
200with astatuslist: the domain is registered (the list shows things likeclient holdorpending delete). -
404: the registry has no record, which usually means it is not registered.
rdap.org documents a limit of 10 requests per 10 seconds and returns 429 above it. Registries' own terms matter too: Verisign's RDAP terms (for .com and .net) forbid using it to "enable high volume, automated, electronic processes". So use RDAP only for the few domains DNS could not resolve, not for your whole list. That is what the script does.
How do I check a list of domains in Python?
Standard library only (tested with Python 3.9). One domain per line in domains.txt:
import csv import ipaddress import json import sys import time import urllib.error import urllib.parse import urllib.request DOH = "https://cloudflare-dns.com/dns-query" UA = "domain-check-example/1.0 (contact: you@example.com)" PAUSE = 1.0 # seconds between requests; keep it polite RCODES = {0: "NOERROR", 2: "SERVFAIL", 3: "NXDOMAIN", 5: "REFUSED"} def get_json(url, headers): req = urllib.request.Request(url, headers={"user-agent": UA, **headers}) try: with urllib.request.urlopen(req, timeout=10) as resp: return resp.status, json.load(resp) except urllib.error.HTTPError as e: return e.code, None finally: time.sleep(PAUSE) def dns(name, rtype): """Return (status, [answers of that type]) from Cloudflare DoH JSON.""" url = DOH + "?" + urllib.parse.urlencode({"name": name, "type": rtype}) code, data = get_json(url, {"accept": "application/dns-json"}) if data is None: return "DoH HTTP %s" % code, [] status = RCODES.get(data["Status"], str(data["Status"])) want = {"A": 1, "NS": 2, "AAAA": 28}[rtype] answers = [a["data"] for a in data.get("Answer", []) if a["type"] == want] if status == "NOERROR" and not answers: status = "NODATA" # the name exists, but has no record of this type return status, answers def rdap(domain): """Ask rdap.org (it redirects to the registry's RDAP server).""" code, data = get_json("https://rdap.org/domain/" + domain, {"accept": "application/rdap+json"}) if code == 404: return "not found in RDAP" if code != 200 or data is None: return "RDAP HTTP %s" % code return "registered: " + ", ".join(data.get("status", [])) def http(domain): req = urllib.request.Request("https://" + domain + "/", headers={"user-agent": UA}) try: with urllib.request.urlopen(req, timeout=10) as resp: return str(resp.status) except urllib.error.HTTPError as e: return str(e.code) # the server answered, just not with 2xx except urllib.error.URLError as e: return type(e.reason).__name__ # TLS error, refused, DNS, ... except Exception as e: # timeouts and other socket errors return type(e).__name__ finally: time.sleep(PAUSE) def check(domain): row = {"domain": domain, "a": "", "aaaa": "", "ns": "", "verdict": "", "extra": ""} a_status, a = dns(domain, "A") row["a"] = a_status if a_status in ("NXDOMAIN", "SERVFAIL"): row["verdict"] = "does not resolve" if a_status == "NXDOMAIN" else "DNS broken" row["extra"] = rdap(domain) # registered or not? DNS cannot tell you return row aaaa_status, aaaa = dns(domain, "AAAA") ns_status, _ = dns(domain, "NS") row["aaaa"], row["ns"] = aaaa_status, ns_status ips = a + aaaa if not ips: row["verdict"] = "exists, no address" elif all(not ipaddress.ip_address(ip).is_global for ip in ips): row["verdict"] = "resolves to non-public IP" row["extra"] = ips[0] else: row["verdict"] = "resolves" row["extra"] = "https " + http(domain) return row if __name__ == "__main__": domains = [d.strip().lower() for d in open(sys.argv[1]) if d.strip()] rows = [check(d) for d in domains] out = csv.DictWriter(sys.stdout, fieldnames=rows[0].keys()) out.writeheader() out.writerows(rows) I picked seven names that each hit a different branch, including two public test domains (dnssec-failed.org is deliberately signed wrong, and expired.badssl.com serves an expired certificate):
example.com wikipedia.org googlemail.co.uk localtest.me expired.badssl.com dnssec-failed.org this-name-should-not-exist-7f3k2.com python3 check_domains.py domains.txt > report.csv Output, identical on two runs on 2026-12-01 (about 30 seconds each with the 1-second pause):
domain,a,aaaa,ns,verdict,extra example.com,NOERROR,NOERROR,NOERROR,resolves,https 200 wikipedia.org,NOERROR,NOERROR,NOERROR,resolves,https 200 googlemail.co.uk,NODATA,NODATA,NOERROR,"exists, no address", localtest.me,NOERROR,NOERROR,NOERROR,resolves to non-public IP,127.0.0.1 expired.badssl.com,NOERROR,NODATA,NODATA,resolves,https SSLCertVerificationError dnssec-failed.org,SERVFAIL,,,DNS broken,registered: client transfer prohibited this-name-should-not-exist-7f3k2.com,NXDOMAIN,,,does not resolve,not found in RDAP How to read it:
-
googlemail.co.ukhas name servers but no address. Agethostbynamecheck would call it dead; it is not. -
localtest.meresolves, but only to loopback, so nothing on the internet can reach it.ipaddress'sis_globalcatches private and loopback ranges. -
expired.badssl.comis fine in DNS and broken over HTTPS. Its NS row is NODATA because it is a subdomain; name servers sit on the zone (badssl.com), not on every host name. -
dnssec-failed.orgreturns SERVFAIL, yet RDAP shows it is registered. "Does not resolve" and "not registered" are different answers. - The made-up
.comname is NXDOMAIN in DNS and 404 in RDAP: not registered.
What I did not see in these runs: a 429 from rdap.org, a timeout, a network error on the DoH call (that one is not caught and will raise), and a registered domain on clientHold/serverHold, which typically shows as NXDOMAIN in DNS and 200 in RDAP. The code handles the first two by returning the status or exception name, but I have not tested them.
How do I make it faster for thousands of domains?
With a 1-second pause, a resolving domain costs four requests (A, AAAA, NS, HTTPS), so about 4 seconds; 1,000 domains is over an hour. Things that help:
- Run domains in parallel with
concurrent.futures.ThreadPoolExecutor, keeping the pause per worker. Cloudflare does not publish a rate limit for the JSON endpoint, so start small. - Skip the AAAA, NS or HTTPS steps if you only need "exists or not". The A lookup alone separates NXDOMAIN, NODATA and SERVFAIL.
- Keep RDAP for the NXDOMAIN and SERVFAIL rows only, and respect the 10-per-10-seconds limit.
Is there a hosted option for the DNS part?
I built an Apify Actor, DNS Lookup in Bulk – MX, SPF, DMARC & DNS Records, that covers the DNS half of this. For this job, paste your domain list and select only A under record types: it looks up the A record for each domain and returns one row per domain.
Input for that check (field names from the README):
{ "domains": ["example.com", "https://www.example.org/about", "this-name-should-not-exist-7f3k2.com"], "recordTypes": ["A"], "maxItems": 1000 } What it does and does not do, from the README:
- Each row has a
statusofNOERROR,NXDOMAINorNODATA, and therecords. URLs, upper case and internationalized names in the list are normalized; duplicates are looked up once. - It asks the run's own system resolver first and falls back to Cloudflare DNS-over-HTTPS only when that fails. A lookup that fails on both (SERVFAIL or timeout) writes no row; the domain and the reason go to the run summary instead, and it is not charged.
- DNS only. No WHOIS, no RDAP, so it cannot tell you whether an NXDOMAIN domain is registered. No HTTP check either: a domain with an IP and a dead website shows as
NOERROR. Use the RDAP and HTTPS parts of the script above for those. - Cost: US$0.20 per 1,000 rows plus US$0.0005 per run start. With A only, 1,000 domains is 1,000 rows, so about US$0.20. Apify's free plan includes US$5 of usage a month.
- About 11–15 rows per second; one run lasts at most about 60 minutes; a list can hold up to 10,000 domains.
It is not affiliated with or endorsed by Cloudflare, rdap.org, any registry or any DNS provider.
FAQ
What does NXDOMAIN mean for a domain?
NXDOMAIN (DNS response code 3) means the name does not exist in DNS. For a registrable domain, the usual causes are that it was never registered, it expired, or the registrar or registry put it on hold so it is no longer published. Check RDAP to see which one.
Is a domain with no A record dead?
Not necessarily. If the answer is NOERROR with no A or AAAA record (NODATA), the domain exists and its name servers answer; it just has no web address. Mail-only and parked domains often look like this. Check its NS and MX records before you drop it from a list.
Can a domain be registered but not resolve?
Yes. A registered domain with no name servers, with broken name servers, with broken DNSSEC, or on clientHold/serverHold does not resolve. In the test above, dnssec-failed.org returned SERVFAIL while RDAP showed it as registered. DNS answers "does it resolve", RDAP answers "is it registered".
Should I use WHOIS or RDAP to check registration?
RDAP. It returns structured JSON over HTTPS, and rdap.org redirects each query to the right registry, so there is no text parsing per TLD. Keep the volume low: rdap.org allows 10 requests per 10 seconds, and registry terms such as Verisign's forbid high-volume automated use.
Is socket.gethostbyname enough to check if a domain exists?
It is enough for a yes/no "did I get an IPv4 address". It cannot tell NXDOMAIN from NODATA or SERVFAIL, it ignores IPv6-only domains, and it depends on your local resolver and hosts file. For a list you will act on, read the DNS response code instead.
How do I check if an email domain is active?
Start with the same DNS check: NXDOMAIN means the domain does not exist, so no mail can be delivered to it. Then look at the MX record. If there is no MX at all, senders fall back to the domain's A/AAAA address (RFC 5321 §5.1); an MX of . (a "null MX", RFC 7505) means the domain says it accepts no mail.
Which state do you treat as "dead" in your own lists: NXDOMAIN only, or anything without a working website?
Disclosure: I built the Apify Actor mentioned in this post.

