Skip to content

Instantly share code, notes, and snippets.

@alvesvaren
Created August 4, 2018 10:36
Show Gist options
  • Save alvesvaren/1254116a31b7c1f748b7ee46e5f8a221 to your computer and use it in GitHub Desktop.
Save alvesvaren/1254116a31b7c1f748b7ee46e5f8a221 to your computer and use it in GitHub Desktop.
A python script to set godaddy dns server to your ip, schedule this to run periodically.
import requests
import json
# This script is used to check and update your GoDaddy DNS server to the IP address of your current internet connection.
# First go to GoDaddy developer site to create a developer account and get your key and secret
# https://developer.godaddy.com/getstarted
# Update the first 4 varriables with your information
# This is a script rewrited to python from powershell, original script is available at https://github.com/markafox/GoDaddy_Powershell_DDNS
domain = 'domain name'
name = 'subdomain name'
key = 'api key'
secret = 'api secret'
headers = {}
headers['Authorization'] = f'sso-key {key}:{secret}'
headers['User-Agent'] = 'python-ddns/1.0'
headers['content-type'] = "application/json"
result = requests.get(f'https://api.godaddy.com/v1/domains/{domain}/records/A/{name}', headers=headers)
content = result.json()
dns_ip = content[0]['data']
current_ip = requests.get('http://ipinfo.io/json').json()['ip']
print(dns_ip, ':', current_ip)
if current_ip != dns_ip:
result = requests.put(f'https://api.godaddy.com/v1/domains/{domain}/records/A/{name}', json.dumps([{'data': f'{current_ip}', 'ttl': 3600}]), headers=headers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment