This Python script is designed to check the current public IPv4 and IPv6 addresses of a system and compare them with Digital Ocean DNS records. If any discrepancies are found, the script will automatically update the DNS records to reflect the current public IP addresses. This can be useful for maintaining accurate DNS records for services hosted on dynamic IP addresses.
Before using this script, make sure you have the following prerequisites installed:
- Python 3.10
- Pipenv (Python package manager and virtual environment tool)
You will also need a Digital Ocean API token for authentication.
- Clone the repository or download the script:
git clone https://github.com/yourusername/public-ip-dns-updater.git
- Change into the project directory:
cd auto-domain
- Create a virtual environment and install the required Python packages using Pipenv:
pipenv install
- Copy the provided
.env.example
file and create a new.env
file:
cp .env.example .env
- Edit the
.env
file to include your specific configuration:
DOMAIN_NAME=example.com
COMBINED_SUBDOMAIN=www # @ for root domain
IPV4_SUBDOMAIN= # @ for root domain
IPV6_SUBDOMAIN= # @ for root domain
DIGITALOCEAN_TOKEN=your_digital_ocean_api_token_here
Note: Only set
IPV4_SUBDOMAIN
orIPV6_SUBDOMAIN
if you want to update the A or AAAA records specifically. If you want to update both to the same subdomain, setCOMBINED_SUBDOMAIN
instead.
Run the script main.py
using Pipenv:
pipenv run python main.py
The main.py
script will perform the following steps:
- Fetch the current public IPv4 and IPv6 addresses of your system.
- Query Digital Ocean's API to retrieve the existing DNS records for the specified domain/subdomain.
- Compare the current public IP addresses with the existing DNS records.
- If there is a mismatch, update the DNS records with the current IP addresses using Digital Ocean's API.
You can schedule the main.py
script to run periodically (e.g., using a cron job) to ensure your DNS records are always up to date.
The script accept the following optional arguments:
-v
or--warning
to enable warning messages-vv
or--info
to enable info messages-q
or--quiet
to disable all messages
Contributions to this project are welcome. If you encounter any issues or have suggestions for improvements, please create an issue or submit a pull request on the GitHub repository.
This script is licensed under the MIT License. See the LICENSE file for details.
Disclaimer: Use this script responsibly and ensure you have proper authorization to modify DNS records. Be aware that updating DNS records can affect your online services, so use it with caution.