Skip to content

Instantly share code, notes, and snippets.

  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Cloudflare bulk delete dns
This module is contains a handy tool to bulk delete DNS records from Cloudflare DNS via API
git clone
cd bb15b3fc54ec6cbe7476b52c49e7c4aa
python3 ./ your_api_token zone_id
import requests as r
import sys
ZONE_ID = ""
def del_dns(id: str, api_token: str = API_TOKEN, zone_id: str = ZONE_ID) -> str:
url = f"{zone_id}/dns_records/{id}"
headers = {"Authorization": f"Bearer {api_token}"}
res = r.delete(url, headers=headers)
if res.ok:
print("\tDeleted:", res.json())
def del_all_dns(api_token: str = API_TOKEN, zone_id: str = ZONE_ID):
url = f"{zone_id}/dns_records"
headers = {"Authorization": f"Bearer {api_token}"}
params = {
"per_page": 100,
while True:
print("\n\tDeleting ALL dns records\n")
res = r.get(url, params=params, headers=headers)
if res.ok:
result = res.json().get("result")
result_info = res.json().get("result_info")
total_count = result_info.get("total_count")
print(f"\tTotal DNS count: {total_count}!")
if total_count == 0:
for record in result:
del_dns(id=record.get("id"), api_token=api_token, zone_id=zone_id)
if __name__ == "__main__":
del_all_dns(api_token=sys.argv[1], zone_id=sys.argv[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment