Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 3 min read

Domain expiry monitoring for client sites: a small script and a renewal checklist

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, s

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.

  1. Record the registrar and the account owner for every domain in the same place as the hosting details.
  2. Register in the client's name, with a role-based contact address that more than one person reads.
  3. Turn on auto-renew and note the card expiry month next to it.
  4. Lock the domain at the registrar and keep the transfer code somewhere the client can reach.
  5. Set two alerts: the script at 60 days, and a calendar reminder at 30 days.
  6. Check the nameservers and MX records after any registrar change, not just the website.
  7. 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.

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.