This script automatically updates a Cloudflare DNS record with the current external IP address of the machine running the script. It is designed to be a more readable and maintainable Python version of an older shell script.
- Configuration Loading: Reads configuration parameters from a JSON file.
- IP Address Handling: Retrieves the current external IP address and checks if it has changed since the last update.
- Cloudflare Integration: Uses Cloudflare API to get Zone ID and Domain ID, and updates the DNS record if the IP address has changed.
- Error Handling: Provides error messages and retries for network operations to ensure reliability.
- Usage: The script is designed to be run from the command line with a configuration file as an argument.
- Python 3.x
requests
library (can be installed viapip install requests
)
- Install the
requests
library:pip install requests
- Create a configuration file (
config.json
) with the following structure:
{
"LAST_IP_FILE": "last_ip.txt",
"CF_EMAIL": "[email protected]",
"CF_TOKEN": "your-cloudflare-api-token",
"CF_ZONE_NAME": "example.com",
"CF_DOMAIN_NAME": "sub.example.com"
}
- Run the script:
python update_cloudflare_dns.py config.json