Skip to content

Instantly share code, notes, and snippets.

@gabriel-samfira
Created June 18, 2019 11:47
Show Gist options
  • Save gabriel-samfira/11d98e121222bc26a23283c79553ce8d to your computer and use it in GitHub Desktop.
Save gabriel-samfira/11d98e121222bc26a23283c79553ce8d to your computer and use it in GitHub Desktop.
quick and dirty dynamic DNS updater for digital ocean
#!/usr/bin/env python3
import requests
import digitalocean
import sys
TOKEN="your secret goes gere"
DOMAIN="example.com"
RECORD="my-record"
myIP = requests.get("https://simplestreams.samfira.com/ip").text.rstrip("\n")
dom = digitalocean.Domain(token=TOKEN)
dom.name = DOMAIN
records = dom.get_records()
for rec in records:
if rec.name == RECORD and rec.type == "A":
if rec.data == myIP:
sys.exit(0)
rec.data = myIP
rec.save()
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment