If you look after more than a handful of client sites, you will eventually inherit a domain whose renewal depends on a card nobody remembers. Hosting monitors tell you when a site is down. Almost none of them tell you, six weeks early, that the domain itself is about to expire. This post is a small script that does that, plus the checklist we pair it with.
Why uptime checks are not enough
An uptime monitor fires after the damage starts. By then the DNS records may already be gone, the mailboxes are bouncing, and the registrar's parked page is serving ads under your client's name. The fix is to watch the expiry date as data, and alert while there is still time to pay.
The lookup does not need scraping. Registries publish expiry dates through RDAP, a JSON replacement for WHOIS described in RFC 9083. A public bootstrap service redirects each query to the right registry.
The script
It reads a list of domains, asks RDAP for the expiry event, and prints anything due within a threshold. Standard library only.
import json, sys, urllib.request, urllib.error
from datetime import datetime, timezone
WARN_DAYS = 60
def expiry(domain):
url = f"https://rdap.org/domain/{domain}"
req = urllib.request.Request(url, headers={"Accept": "application/rdap+json"})
with urllib.request.urlopen(req, timeout=15) as r:
data = json.load(r)
for ev in data.get("events", []):
if ev.get("eventAction") == "expiration":
return datetime.fromisoformat(ev["eventDate"].replace("Z", "+00:00"))
return None
def main(path):
now = datetime.now(timezone.utc)
for line in open(path):
domain = line.strip().lower()
if not domain or domain.startswith("#"):
continue
try:
when = expiry(domain)
except urllib.error.HTTPError as e:
print(f"CHECK {domain}: registry answered {e.code}")
continue
except Exception as e:
print(f"CHECK {domain}: lookup failed ({e})")
continue
if when is None:
print(f"CHECK {domain}: no expiry date published")
continue
days = (when - now).days
flag = "RENEW" if days <= WARN_DAYS else "ok"
print(f"{flag:7} {domain}: {when:%d %b %Y} ({days} days)")
main(sys.argv[1])
Put one domain per line in domains.txt, run python3 expiry.py domains.txt, and send the output to wherever your team already looks. A weekly cron job is enough; domains do not expire on a Tuesday afternoon by surprise if you check every week.
Two honest limits. Some registries redact or omit the expiry event, which is why the script prints CHECK rather than staying silent: a missing date is something a human should look at. And RDAP tells you what the registry says, not whether auto-renew is switched on at your registrar. Try it against one domain you know the real date for before you trust it across a client list.
The renewal checklist that goes with it
The script catches the date. The checklist stops the date being a problem.
- Record the registrar and the account owner for every domain in the same place as the hosting details.
- Register in the client's name, with a role-based contact address that more than one person reads.
- Turn on auto-renew and note the card expiry month next to it.
- Lock the domain at the registrar and keep the transfer code somewhere the client can reach.
- Set two alerts: the script at 60 days, and a calendar reminder at 30 days.
- Check the nameservers and MX records after any registrar change, not just the website.
- Agree who pays and write it into the support contract, so renewal is never "someone else's job".
When a domain does lapse
Most registries give a short grace period before release, and the restore route is nearly always through the original registrar. Contact them the same day. While you wait, move mail to a temporary address if you can, and list every service that uses the domain: DNS-hosted verification records, payment provider callbacks, analytics properties and any listings that carry the address. Those are the things that break quietly.
A note on the search side
A domain that stops resolving cannot hold rankings, and pages that return errors for long enough drop out of results. When we do SEO services in Birmingham, confirming that the domain, DNS and email are healthy comes before any keyword work, because every other fix depends on the address working.
Rocky V is Head of Operations at DigitalCave, an all-in-one web design, SEO and digital marketing agency in the West Midlands.
Top comments (2)
One case in the script is worth splitting out:
HTTPError404.From a registry, 404 means "no such domain", and on a client list that is the worst possible answer, because the name has already been deleted and may be up for grabs. But rdap.org can also come back with a 404 when it has no RDAP server for that TLD. Right now both land in the same
CHECK ... registry answered 404line, and on a Monday morning that line is easy to skim past.Two other things show up once the list includes client ccTLDs:
CHECKpermanently, so they need a second source rather than a human glance each week.Retry-Aftermeasured in hours after a burst of queries, so a weekly cron that walks a long .uk list in one go can trip it.For the TLDs RDAP can't answer, a bulk WHOIS API (Whoisfreaks.com/products/bulk-whois-api) that switches between RDAP and port-43 WHOIS per TLD fills the hole. It takes 100 domains per call and returns the expiry date, registrar and EPP status in one shape, so the
RENEW/oklogic doesn't change. Keeping your RDAP path for the gTLDs and only sending the leftovers there keeps the cost close to zero.Your checklist point 4 (lock plus transfer code) pairs well with this, too: if a weekly run ever shows
clientTransferProhibiteddisappearing from a client domain's status, someone has started a transfer.When you onboard a client whose previous agency already let the domain or hosting lapse, do you usually have an exported copy of their old pages and blog posts to rebuild from or end up pulling from caches?