Skip to content

Instantly share code, notes, and snippets.

@supersonictw
Created October 23, 2023 02:32
Show Gist options
  • Save supersonictw/24434c20ccb45f4cb687347c847d5f2f to your computer and use it in GitHub Desktop.
Save supersonictw/24434c20ccb45f4cb687347c847d5f2f to your computer and use it in GitHub Desktop.
Flush Cloudlflare DNS records
#!/bin/bash
# Flush Cloudlflare DNS records
CF_TOKEN=""
ZONE_ID=""
QUERY_RECORDS() {
curl -s -X GET https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records?per_page=500 \
-H "Authorization: Bearer ${CF_TOKEN}" \
-H "Content-Type: application/json"
}
REMOVE_RECORD() {
curl -s -X DELETE https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records/$1 \
-H "Authorization: Bearer ${CF_TOKEN}" \
-H "Content-Type: application/json"
printf "\n"
}
QUERY_RECORDS | jq .result[].id | tr -d '"' | (
while read id; do
REMOVE_RECORD $id &
done
)
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment