Skip to content

Instantly share code, notes, and snippets.

@jovimon
Last active Oct 7, 2021
Embed
What would you like to do?
CDMon dynamic DNS IP update script
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Python script to update CDMon dynamic DNS
#
# @author = @jovimon
# @version = 0.1.20200930
#
# Prerequisites: sudo pip install requests / sudo apt install python-requests
#
# Based on:
# https://ticket.cdmon.com/es/support/solutions/articles/7000005922-api-de-actualizaci%C3%B3n-de-ip-del-dns-gratis-din%C3%A1mico
#
# You can find the last version on: https://gist.github.com/jovimon/498569a2bf04a9a3f91c2d9bc0b62f35
#
# Updated to python 3 as per the comments to the gist.
import requests
import hashlib
import datetime
# MODIFY HERE
user = 'example-user'
password = 'example-password'
# If you want, you can change how you obtain your external IP address.
# newip must contain just the IP without anything else, even spaces or newlines.
newip = requests.get('http://ipecho.net/plain').text
# newip = requests.get('http://icanhazip.com').text
# DO NOT MODIFY BELOW THIS LINE
# Obtain current date and time
curr_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# Obtain password digest that will be used in the update request
pw_digest = hashlib.md5(bytes(password,"ascii")).hexdigest()
# Build the update URL
url = "https://dinamico.cdmon.org/onlineService.php?enctype=MD5&n=%s&p=%s&cip=%s" % (user, pw_digest, newip)
# Make the update request
r = requests.get(url)
# Check if everything went fine. If not, show the error.
if r.text.find('customok') < 0:
print("%s - Update error!\nResponse received: %s\nCheck cdmon KB for problems." % (curr_date, r.text))
exit(-1)
else:
print("%s - Update successful!" % curr_date)
@woonaval
Copy link

woonaval commented Sep 29, 2021

Hi, I tried to run this script in Debian 11 and the package "python-requests" can't be found. I tried installing with dpkg manually but it has a lot of unmet dependencies... any idea? Thank you!

Edit: if someone would have this issue: I changed the first line from python to python3, like this:
#!/usr/bin/env python3

@jovimon
Copy link
Author

jovimon commented Oct 7, 2021

thanks @woonaval, just updated the first line with what you said.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment