Dynu Client in Python - Dynamic DNS

Dynamic Ip was something which restricts people to test or launch their small web applications. Later some websites started offering their sub domains for free to normal people, so they could get a permanent web address for web application/sites.

All you need to do is,
  • Point your dynamic IP to the provided subdomain.
  • Update the dynamic IP regularly. So IP change won't restrict app's performance and gives near to 100% uptime.

dynu.com is a pioneer in providing this service. In this post, I'm sharing python code which regularly updates your IP to dynu's dynamic service. In the code, from different service we will retrieve current IP address. Next we will load different parameters needed, in addition the password is programmatically converted to md5 for security reasons. Along with the parameters, new IP is updated to Dynu Dynamic DNS Service.

Please note that the code will update only IPv4 address. Please modify the code and configuration if you have a IPv6 service.
Check the GitHub repo for complete details.

Add this code to a cron job(Linux) or task scheduler(windows)

Python Libraries required,


import configparser import requests import re import hashlib configParser = configparser.RawConfigParser() configFilePath = r'dynuParams.config' configParser.read(configFilePath) dynuUpdateUrl = configParser.get('dynuParams', 'dynuUpdateUrl') hostName = configParser.get('dynuParams', 'hostName') myipv6 = configParser.get('dynuParams', 'myipv6') username = configParser.get('dynuParams', 'username') ipSources = configParser.get('dynuParams', 'ipSources') password = configParser.get('dynuParams', 'password') print("Dynu Client Started") try: m = hashlib.md5() m.update(password.encode('utf-8')) md5Password = m.hexdigest() print(md5Password) for ipSource in ipSources.split(","): print("IP fetching source - "+ipSource) response = requests.get(ipSource) ip = response.json()["ip"] print("IP found - "+ip) if (re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", ip)): break; print("Started updating IP in Dynu") response = requests.get(url=dynuUpdateUrl, params={"hostname": hostName, "myip": ip, "myipv6": myipv6, "username": username, "password": md5Password}) print("Response from Dynu - "+str(response.content)) except Exception as e: print ("Exception - "+str(e))


Popular posts from this blog

The beginning of Data Quest

Setting up Python Flask server on internet via Port forwarding

Automate Blog Post creation using Blogger APIs and Python

Creation of Orphan Process in Linux using Python

How to remove TWRP from Android Phone - Nubia Z11 miniS