Auto register expired domains using DNSimple API and Python
There’s a domain that will soon be available (at the moment it is in pending delete status) and I’d like to own it so much. But I don’t want to pay for backorder services, which may cost me much more than the original value of that domain. So I thought of making a script to register the domain as soon as it’s released. And here it is:
from dnsimple import DNSimple
import time
import daemon
import logging
dns = DNSimple(email="[email protected]", api_token="YOUR_API_TOKEN")
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
fh = logging.FileHandler("./your-desired-domain.log")
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
logger.addHandler(fh)
def register():
try:
dns.register('your-desired-domain.com', A_CONTACT_ID_NUMBER)
except Exception as e:
logger.info(e)
return False
return True
def run_register_daemon():
i = 1
while True:
logger.info("Run: " + str(i))
if register():
logger.info("Domain registered.")
break
i = i + 1
time.sleep(20)
def run():
with daemon.DaemonContext(files_preserve = [fh.stream]):
run_register_daemon()
if __name__ == "__main__":
run()
Obviously, you need a DNSimple account (with a working plan) in order for the script to do its job. Replace `email` and `api_token` with your email and API token which can be easily obtained in the account page. You also need to create a contact with a valid zipcode, then replace `A_CONTACT_ID_NUMBER` with this contact ID number.
The script uses this Python package: https://github.com/mikemaccana/dnsimple-python and this package: https://pypi.python.org/pypi/python-daemon. Make sure you already have a working copy of them. Don’t use `pip install dnsimple-python` or `easy_install dnsimple-python` because they won’t give you the latest version. You may also need to “tweak” the library so that you can really work with it. Don’t worry, just do it, it doesn’t hurt.
Ah, and did you replace `your-desired-domain.com` with your desired domain? Good, now just run the script:
$ python register_domain.py
Now it will run in background and exit until the expired domain is registered. You don’t have to run it with `nohup` or `&` because the script won’t be killed after you quit the shell. If you’re curious about what it is doing in background, just look at the log file:
$ tail -f your-desired-domain.log
Now, keep calm and wait until DNSimple inform you good news via email in about some days. If it will not, then you may need to wait for longer and longer (1 year? 2 years? I don’t know). Keep in mind that as the registration is done, you will be charged for your new domain. I could register my wanted domain using this script. I’m not sure that it will run successfully for you but you know, doing something is better than doing nothing.