Hack of the day: simple python script for maintaining DNS records in Namecheap

By | February 17, 2023

I needed to add an include to the SPF record for my domain today, one which I sincerely hope will be temporary, but I fear the reason for the addition will be lost to the mists of time and I’ll be looking at my SPF record in five years saying to myself “wtf is that there?”

The obvious solution is to put a comment above or next to the SPF record explaining the change, but that’s impossible when your SPF records are maintained through a web portal, in my case Namecheap’s. Namecheap does not allow comments to be associated with DNS records created through its Advanced DNS management interface.

This finally prompted me to do something I’ve been intending to do for a long time but never got around to, in particular, writing some code to allow me to maintain my Namecheap DNS records in source control with change history rather than directly in the Namecheap web app.

I dug around a bit and found PyNamecheap, but it’s not being maintained and I didn’t want to deal with that. The Namecheap HTTP API is simple enough that I decided to just go ahead and code directly against it rather than using a wrapper library.

The result is namecheap-dns.py, a script which knows how to export DNS records from Namecheap to YAML or import from the same YAML format back into Namecheap. Share and enjoy!

Share

Leave a Reply

Your email address will not be published. Required fields are marked *