Monitoring DNS domain name expiration with dns-domain-expiration-checker

Several years ago I wrote a simple bash script to check the expiration date of the DNS domains I own. At the time I wrote this purely for my own needs but after receiving 100s of e-mails from folks who were using it (and submitting patches) I decided to enhance it to be more useful. As time has gone on Registrar WHOIS data formats have changed and I came to the realization that there is no standard time format for expiration records. I needed a more suitable solution so I spent last weekend re-writing my original script in Python. The new version is available on github and solves all of the issues I previously encountered.

To work around the Registrar WHOIS data format issue I created a list of strings which can be easily extended as new ones are encountered (or changed):

EXPIRE_STRINGS = [ "Registry Expiry Date:",
                   "Domain Expiration Date"

These strings are checked against the WHOIS data returned from whois and if a match is found I save off $NF which should be the date. To get around the date formatting issues I pulled in the dateutil module which does an AMAZING job of normalizing dates. This module allows me to feed it random date formats which are then normalized to datetime objects which I can perform math on. The github README contains several examples showing how to use the script. The most basic form allows you to see expiration data for a domain or a set of domains in a file:

$ --domainname --interactive

Domain Name Registrar Expiration Date Days Left DNC Holdings, Inc. 2020-06-23 16:56:05 1056

If you want to get e-mail notifications when a domain is about to expire you will first need to create a file to pass to the script. Each line contains one domain and an integer to indicate when you want to get a notification for an expiring domain:

$ cat domains 60 60 60 80

To generate e-mails from the command line you can run the script with the file and the SMTP server to relay mail through:

$ --domainfile domains --email --smtpserver smtp.mydomain --smtpto "biff" --smtpfrom "Root"

You can also add the command above to cron to automate the domain expiration notification process (automate cron job creation with ansible shows how to use ansible to automate this). If you use the script and encounter any bugs please shoot me an issue on github.

This article was posted by Matty on 2017-08-02 11:31:00 -0400 EDT