Skip to content

Instantly share code, notes, and snippets.

@syeef
Created February 12, 2020 13:35
Show Gist options
  • Save syeef/041f267ddcf8911a3035447687ae3f20 to your computer and use it in GitHub Desktop.
Save syeef/041f267ddcf8911a3035447687ae3f20 to your computer and use it in GitHub Desktop.
DynamicDNS with Cloudflare (Get current IP Address -> Update DNS record on Cloudflare)
import requests
from requests import get
key = <ENTER CF GLOBAL API KEY>
email = <ENTER CF LOGIN EMAIL>
zone_ID = <ENTER ZONE ID>
record_ID = <ENTER DNS RECORD ID>
ip = get('https://api.ipify.org').text
put = requests.put(
'https://api.cloudflare.com/client/v4/zones/{}/dns_records/{}'.format(
zone_ID, record_ID),
json={
'type': 'A',
'name': <ENTER ZONE NAME>,
'content': ip,
'proxied': False
},
headers={
'X-Auth-Key': key,
'X-Auth-Email': email,
'Content-Type': 'application/json'
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment