Created
October 11, 2023 22:55
-
-
Save randy3k/212ed57a315a89ff6d712fb0f67d6e23 to your computer and use it in GitHub Desktop.
Update Cloudflare ddns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import CloudFlare | |
import requests | |
TOKEN = "" | |
DOMAIN = "" | |
SUBDOMAINS = [] | |
myip = requests.get('https://api.ipify.org').content.decode('utf8') | |
cf = CloudFlare.CloudFlare(token = TOKEN) | |
zones = cf.zones.get(params = {'name': DOMAIN}) | |
if not zones: | |
raise Exception("zone not found") | |
zone_id = zones[0]['id'] | |
dns_records = cf.zones.dns_records.get(zone_id) | |
for dns_record in dns_records: | |
if dns_record['name'].replace("." + DOMAIN, "") in SUBDOMAINS: | |
dns_record_id = dns_record['id'] | |
cf.zones.dns_records.patch(zone_id, dns_record_id, data = { | |
"content": myip | |
}) | |
print("Updated {} with IP {}.".format(dns_record['name'], myip)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment