Skip to content

Instantly share code, notes, and snippets.

@jovimon

jovimon/cdmon_update.py

Last active Sep 30, 2020
Embed
What would you like to do?
CDMon dynamic DNS IP update script
#!/usr/bin/env python
# -*- 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)
@otakuryo

This comment has been minimized.

Copy link

@otakuryo otakuryo commented Sep 27, 2020

Need fix:
import md5 -> import hashlib
pw_digest = md5.new(password).hexdigest() -> pw_digest = hashlib.md5(bytes(password,"ascii")).hexdigest()
print "..."-> print ("...")

@jovimon

This comment has been minimized.

Copy link
Owner Author

@jovimon jovimon commented Sep 30, 2020

Thanks @otakuryo, I updated the gist to python 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.