Dynamic DNS services are all over the internet. Most of them will provide you with a subdomain on a domain that they own. They will host any domain that you want, but there’s usually a charge attached to the service. NO-IP, for example, charges around $10US per month for bring your own domain.
This post will walk you through creating a script that you can run via a cron job or Windows scheduler to periodically update the DNS record of your choosing, provided you have registered the domain with Hover.
Hover has had an API for a long time, but they don’t support it, and won’t help you to access it. There are a lot of GitHub repositories that are available for this task, but they have somewhat recently begun to require two-factor authentication during sign-in which breaks all the scripts that I was able to find online.
Here’s an overview of the steps involved in getting this setup working.
- Update your Hover account on the website to use an authenticator app instead of the default email driven loop it will be set to. This is important because we will be generating the TOTP in the script, and we won’t be able to automatically get the code that is emailed if you’re still using that option.
- When setting up the app, the website will show you a QR code and a secret key. WRITE THIS KEY DOWN! You must have it during configuration of the script.
The next thing we need to do is install Python 3 or later, which you can do on Windows, MacOS or Linux. The screenshots I’m showing below are from Linux, with the commands needed.
sudo apt update && sudo apt install python3 -y
Once that command completes, execute the following to make sure you version is 3.x or higher:
python3 --version
This should return something along the lines of:
Python 3.10.12
If you don’t see output similar to that, you will have to determine the proper way to install Python in your environment.
Now, assuming all went well, and your Python environment is working correctly, you will need to install the Requests package using pip:
pip install requests
This package provides the API to complete the web requests needed to sign in to Hover automatically and update the chosen DNS records. It’s also used to get your public IP from a service, ipify API.
I use VS Code as my editor of choice, and highly recommend you check it out if haven’t already. Assuming you get that setup, we’ll start the project.
First, create a new folder in Visual Studio Code and create a file called update-hover.py. This will be the main file in your script and will contain all the logic for determining your public IP, logging into Hover, and updating the IP address of the record that you designate. Create a second file, called totp.py that will contain the code for the time based one time password (TOTP) used as the second factor when authenticating against hover.com. Additionally, the script uses a config.json file that you’ll need to create that contains the configuration for your hover.com account. A sample file is below:
{
"dnsid": "",
"username": "",
"password": "",
"discoverip": "true",
"srcdomain": "",
"ipaddress": "192.168.1.1",
"totp_secret": "xxxx xxxx xxxx xxxx xxxx xxxx xx"
}
The values are defined below:
- DNSID: The DNSID returned by a call to the script running the -getDNSID option
- username: Your hover account username
- password: Your hover account password
- discoverip: True/False indicating whether or not to use ipify to get your IP
- srcdomain: If set, script will lookup the ip for the domain name and use that
- ipaddress: If set, the script will use the IP to set for the record
- totp_secret: The secret given to you when you setup two factor
Once you have the configuration file setup, you can run the script with update-hover.py using cron or Windows Scheduler to periodically update your IP.
Download the script here: https://www.github.com/pjslauta/hover-dyn-dns.git