Skip to content

Instantly share code, notes, and snippets.

@jovimon jovimon/cdmon_update.py
Last active Jun 14, 2019

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.20190615
#
# 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
import requests
import md5
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 = md5.new(password).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
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.