使用SHELL批量删除Cloudflare解析记录

前言

不得不吐槽下,将一个现有域名添加到Cloudflare时,系统自动导入的几百个不那么正确的解析记录,让人抓狂;这些记录在界面无法快速删除,也不支持跳过导入,暴汗……

解决

还是用码农的思路来解决问题吧:

  • 创建一个有DNS写权限的API_TOKEN(操作地址 https://dash.cloudflare.com/profile/api-tokens
  • 查看待操作域名的 ZONE_ID(在域名概要页面右下角可以看到)
  • 修改下面SHELL脚本对应变量后,多运行几次(懒得写分页了……)
# Set your Cloudflare API key
API_TOKEN="xxxxxxx"

# Set the zone ID for the domain you want to manage
ZONE_ID="yyyyyyy"

# Get all DNS records for the zone
curl -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records" \
     -H "Authorization: Bearer $API_TOKEN" \
     -H "Content-Type: application/json" \
     -s -o records.json

# Parse the JSON response to get the record IDs
RECORD_IDS=$(jq -r '.result[].id' records.json)

# Loop through the record IDs and delete each one
for RECORD_ID in $RECORD_IDS; do
  curl -X DELETE "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$RECORD_ID" \
       -H "Authorization: Bearer $API_TOKEN" \
       -H "Content-Type: application/json" \
       -s
  echo ""
done
文章作者: 若海; 原文链接: https://www.rehiy.com/post/502/; 转载需声明来自技术写真 - 若海

添加新评论