From 6a059e680692102f782ee3a84b6174068a843929 Mon Sep 17 00:00:00 2001 From: Firq Date: Sun, 27 Nov 2022 18:03:11 +0100 Subject: [PATCH] Added error handling if key is not in A or AAAA --- cloudflare_script.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cloudflare_script.py b/cloudflare_script.py index 83a2d9f..ce8c9d3 100644 --- a/cloudflare_script.py +++ b/cloudflare_script.py @@ -31,7 +31,16 @@ def main(): for dnsrecord in dns_records: if ipversion == 'skipping': print(f"DNS Name: {dnsrecord['name']} | ID: {dnsrecord['id']} | Type : {dnsrecord['type']} | IP: {dnsrecord['content']}") - dns_names[dnsrecord['type']].append(dnsrecord["name"]) + + if dnsrecord['type'] in ['A', 'AAAA']: + dns_names[dnsrecord['type']].append(dnsrecord["name"]) + else: + print(f"Cannot resolve record {dnsrecord['name']} because of type {dnsrecord['type']}") + print(f"------ Full DNS record ------\n" + f"{dnsrecord}" + f"\n---------------------------" + ) + with open('cloudflare.json', 'r') as file: values = json.load(file) @@ -55,7 +64,7 @@ def main(): if fullname in dns_names['A']: new_dnsrecords = {"name": fullname, "type": "A", "content": ip_address_new} print(f"Sending request {new_dnsrecords}") - r = cf.zones.dns_records.put(zone_id, dns_record_id, data=new_dnsrecords) + r = cf.zones.dns_records.patch(zone_id, dns_record_id, data=new_dnsrecords) print(r) case '6': @@ -75,7 +84,7 @@ def main(): if fullname in dns_names['AAAA']: new_dnsrecords = {"name": fullname, "type": "AAAA", "content": ip_address_new} print(f"Sending request {new_dnsrecords}") - r = cf.zones.dns_records.put(zone_id, dns_record_id, data=new_dnsrecords) + r = cf.zones.dns_records.patch(zone_id, dns_record_id, data=new_dnsrecords) print(r) case 'skipping': print("Done")