侧边栏壁纸
  • 累计撰写 65 篇文章
  • 累计创建 46 个标签
  • 累计收到 98 条评论

目 录CONTENT

文章目录

cloudflare批量自动删除所有DNS记录

草莓牛奶
2023-08-19 / 0 评论 / 0 点赞 / 417 阅读 / 314 字 / 正在检测是否收录...
温馨提示:
「博客文章out of date 会及时更新,无特殊说明仍然有效,欢迎指正内容中的错误」

手动删除cloudflare的DNS解析记录实在是太费劲了
脚本会使用Cloudflare的API分页功能,每次请求最多100个解析记录,并在完成这批的删除后请求下一批,这样可以确保你只需要运行脚本一次就能删除所有的解析记录。

解决

#!/bin/bash

# Set your Cloudflare API key
API_TOKEN="xxxxxxx"

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

# Initial values
PER_PAGE=100  # Cloudflare API maximum limit per request

while :; do
  # Get DNS records for the zone from the first page
  RESPONSE=$(curl -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records?per_page=$PER_PAGE&page=1" \
       -H "Authorization: Bearer $API_TOKEN" \
       -H "Content-Type: application/json" \
       -s)

  # Check if the result is empty, then break
  NUM_RECORDS=$(echo "$RESPONSE" | jq '.result | length')
  if [ "$NUM_RECORDS" -eq 0 ]; then
    break
  fi

  # Parse the JSON response to get the record IDs
  RECORD_IDS=$(echo "$RESPONSE" | jq -r '.result[].id')

  # 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 -e "Deleted record ID: $RECORD_ID\n"
  done
done

echo "All records deleted successfully."

参考连接

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

0

评论区