DEV Community

Bachir Djoukbala
Bachir Djoukbala

Posted on

How to check hundreds of domains for availability in Python with RDAP (no API key)

I got tired of pasting domain ideas into registrar search boxes one at a time. Checking a few hundred names (a brand shortlist, an expiring-domain hunt, a client's portfolio) is a job for a script, and you do not need a paid WHOIS API for it.

The trick: RDAP, the JSON replacement for WHOIS, is public, free and needs no API key. IANA publishes a bootstrap file that tells you which RDAP server answers for each TLD. A 404 from that server means the domain is not registered. A 200 returns the registrar, creation and expiry dates and the nameservers.

Why not classic WHOIS?

  • Port 43 WHOIS has no standard format, so every registry needs its own parser.
  • Many registries rate limit or block it.
  • RDAP is plain HTTPS and JSON, so one parser covers .com, .org, .net, .dev, .app and most new TLDs.

The script

import asyncio, httpx

BOOTSTRAP = "https://data.iana.org/rdap/dns.json"

async def check(client, tld_map, domain, sem):
    tld = domain.rsplit(".", 1)[1]
    base = tld_map.get(tld)
    if not base:
        return domain, "no RDAP for ." + tld, None
    async with sem:
        for attempt in range(3):
            r = await client.get(f"{base.rstrip('/')}/domain/{domain}")
            if r.status_code == 404:
                return domain, "AVAILABLE", None
            if r.status_code == 200:
                events = {e["eventAction"]: e["eventDate"] for e in r.json().get("events", [])}
                return domain, "taken", events.get("expiration")
            if r.status_code == 429:
                await asyncio.sleep(2 * (attempt + 1))
                continue
            return domain, f"HTTP {r.status_code}", None
    return domain, "rate limited", None

async def main(domains):
    sem = asyncio.Semaphore(5)
    async with httpx.AsyncClient(timeout=25, follow_redirects=True,
                                 headers={"Accept": "application/rdap+json"}) as client:
        boot = (await client.get(BOOTSTRAP)).json()["services"]
        tld_map = {tld: urls[0] for tlds, urls in boot for tld in tlds}
        for row in await asyncio.gather(*(check(client, tld_map, d, sem) for d in domains)):
            print(*row, sep="\t")

if __name__ == "__main__":
    names = ["example.com", "apify.com", "thisnamesurelyfree98765.com", "python.org"]
    asyncio.run(main(names))
Enter fullscreen mode Exit fullscreen mode

Output:

example.com                  taken      2027-08-13T05:00:00Z
apify.com                    taken      2035-06-02T18:14:00Z
thisnamesurelyfree98765.com  AVAILABLE  None
python.org                   taken      2033-03-28T06:00:00Z
Enter fullscreen mode Exit fullscreen mode

(Dates and ordering come from the registry, so yours will differ.)

Things that bite you

  1. Not every TLD has RDAP. .de, .io and a few ccTLDs are missing from the IANA bootstrap file. The script reports them as "no RDAP" instead of guessing. Do not read a missing server as "available".
  2. Rate limits. Registry servers may answer 429 if you hammer them. Keep concurrency at 5 to 10 and back off on 429, as above.
  3. A 404 means "not registered", not "buyable". Premium names, reserved names and registry holds can still be unavailable at the registrar. Treat AVAILABLE as "worth checking at a registrar".
  4. Expiry is the interesting field. Sort by expiration to find domains that lapse soon, which is how most drop-catching lists start.
  5. Normalise input. Strip https://, paths and www., and convert internationalised names with .encode("idna").

If you do not want to run it yourself

I packaged the same logic as an Apify actor, Bulk Domain Availability & WHOIS Checker (RDAP): paste a list of domains, get a dataset (JSON, CSV or Excel) with availability, registrar, created and expiry dates, days until expiry and nameservers. It is pay per event at $0.0008 per domain, so 1,000 domains cost about $0.80. Disclosure: I built it. https://apify.com/rejoicing_shanty/domain-availability-whois-rdap

The script above is free to copy and does the same thing for small lists.

Top comments (0)