Domain Expiration Lookup for Many Domains: Automate It With RDAP and Cron
Checking one domain by hand is easy. Our Domain Expiry Checker does it in a few seconds. Checking forty domains spread across three registrars and two credit cards is where renewals slip. A card expires, an auto-renew charge fails, the reminder email lands in a dead inbox, and you find out when the website goes dark.
A scheduled lookup fixes this. The script below reads a list of domains, asks RDAP for each expiry date, and flags anything that expires within 30 days or sits in the post-expiry grace period.
Why RDAP instead of WHOIS
WHOIS returns plain text, and every registry uses its own format. You end up writing a regex for each TLD. RDAP returns JSON with a standard events array, so one parser covers .com, .org, .io and most other TLDs. ICANN also made RDAP the definitive source for gTLD data in January 2025, and many gTLD registries have since turned their WHOIS servers off.
The free redirector at rdap.org looks up the right registry server for you:
curl -sL https://rdap.org/domain/example.com | jq '.events'
The script
Save this as check_expiry.py. It uses only the Python standard library.
#!/usr/bin/env python3
"""Print days until expiry for each domain in domains.txt, using RDAP."""
import json
import sys
import urllib.request
from datetime import datetime, timezone
WARN_DAYS = 30
def expiry(domain):
req = urllib.request.Request(
f"https://rdap.org/domain/{domain}",
headers={"Accept": "application/rdap+json", "User-Agent": "expiry-check/1.0"},
)
with urllib.request.urlopen(req, timeout=15) as resp:
data = json.load(resp)
for event in data.get("events", []):
if event.get("eventAction") == "expiration":
return datetime.fromisoformat(event["eventDate"].replace("Z", "+00:00")), data.get("status", [])
return None, data.get("status", [])
def main(path):
now = datetime.now(timezone.utc)
exit_code = 0
for line in open(path):
domain = line.strip()
if not domain or domain.startswith("#"):
continue
try:
exp, status = expiry(domain)
except Exception as err:
print(f"{domain}\tERROR\t{err}")
exit_code = 1
continue
if exp is None:
print(f"{domain}\tUNKNOWN\tno expiration event in RDAP")
continue
days = (exp - now).days
flag = "WARN" if days <= WARN_DAYS or "auto renew period" in status else "ok"
print(f"{domain}\t{exp.date()}\t{days}d\t{flag}")
if flag == "WARN":
exit_code = 2
sys.exit(exit_code)
if __name__ == "__main__":
main(sys.argv[1] if len(sys.argv) > 1 else "domains.txt")
Put one domain per line in domains.txt. Lines starting with # are skipped, so you can group domains by client or registrar:
# main sites
github.com
wikipedia.org
# country-code
bbc.co.uk
denic.de
Run it:
python3 check_expiry.py domains.txt
github.com 2028-10-09 698d ok
wikipedia.org 2027-01-13 62d ok
bbc.co.uk 2034-12-13 2954d ok
denic.de ERROR HTTP Error 404: Not Found
A domain inside the 30-day window shows WARN instead of ok. The script exits with code 2 if any domain needs attention and code 1 if a lookup failed. Cron and CI systems can act on those codes.
A few details worth knowing:
- The User-Agent header matters. Some registries, including the .org registry, return
403 Forbiddento requests without one. - The
auto renew periodcheck catches a common false negative. After a .com expires, the registry rolls the date forward a year while your registrar waits for payment. A plain date check reports the domain as fine. The RDAP status field shows the truth. - Some ccTLDs don't give you an expiry date. DENIC (.de) doesn't publish one, so the lookup above fails. Other registries answer but leave the date out, and the script prints
UNKNOWN. Track those domains through your registrar.
Schedule it with cron
Run the check every Monday at 08:00 and email the output only when something needs attention:
0 8 * * 1 cd /opt/domain-check && python3 check_expiry.py domains.txt > report.txt || mail -s "Domain expiry warning" [email protected] < report.txt
The || sends mail only when the script exits non-zero. Your server needs a working mail command (from mailutils or s-nail). If it doesn't have one, pipe the report to a Slack or Teams webhook with curl instead.
Weekly is often enough. With a 30-day warning window you get four or five alerts before the date, which leaves time to fix a failed payment.
Run it in CI instead
If you'd rather not keep a server for this, a scheduled GitHub Actions workflow works too:
name: domain-expiry
on:
schedule:
- cron: "0 8 * * 1"
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: python3 check_expiry.py domains.txt
When the script exits non-zero, the job fails and GitHub emails the repository's watchers.
Keep the list honest
The script only watches the domains you give it. Once a quarter, export the domain list from each registrar account and compare it with domains.txt. Look for domains someone registered for a campaign and forgot, and for domains that should move to the main registrar account. Consolidating to one or two registrars means fewer logins, fewer cards and fewer reminder emails to miss.
For a quick one-off check, the Domain Expiry Checker is still faster than opening a terminal.