Created
June 20, 2020 11:56
-
-
Save pauladams8/ed617537625eafb09bb267f9a181e5ef to your computer and use it in GitHub Desktop.
Delete all Cloudflare DNS records
This file contains hidden or 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 | |
CF_EMAIL = None | |
CF_API_KEY = None | |
ZONE_NAME = None | |
client = CloudFlare.CloudFlare(email=CF_EMAIL, token=CF_API_KEY, raw=True) | |
zone = client.zones.get(params = { | |
'name': ZONE_NAME | |
})['result'][0] | |
response = client.zones.dns_records.get(zone['id']) | |
dns_records = response['result'] | |
page = response['result_info']['page'] | |
total_pages = response['result_info']['total_pages'] | |
while page < total_pages: | |
page += 1 | |
response = client.zones.dns_records.get(zone['id'], params = { | |
'page': page | |
}) | |
dns_records += response['result'] | |
for dns_record in dns_records: | |
print('ℹ️ Deleting DNS record %s hosted at %s' % (dns_record['id'], dns_record['name'])) | |
client.zones.dns_records.delete(zone['id'], dns_record['id']) | |
print('✅ Deleted DNS record') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment