Hi, I just want to note this script. Maybe someone needs it too. This script is to delete ip access rules in bulk
Requirements
CF_ZONE_ID
=> Your domain zone id
CF_AUTH_EMAIL
=> Your cloudflare email
CF_AUTH_KEY
=> Your global auth key (check here)
#!/bin/bash
# Cloudflare Settings
CF_ZONE_ID=""
CF_AUTH_EMAIL=""
CF_AUTH_KEY=""
CF_URL="https://api.cloudflare.com/client/v4/zones/$CF_ZONE_ID/firewall/access_rules/rules"
# Get the list of IP addresses and total
JSON=$(curl -s -X GET "$CF_URL?mode=block&configuration_target=ip&page=1&per_page=1000" -H "Content-Type: application/json" -H "X-Auth-Email: $CF_AUTH_EMAIL" -H "X-Auth-Key: $CF_AUTH_KEY")
TOTAL=$(echo $JSON | jq -r .result_info.total_count)
# Loop through the IP addresses and delete them
for (( c=0; c<$TOTAL; c++ )) do
ID=$(echo $JSON | jq -r .result[$c].id);
IP=$(echo $JSON | jq -r .result[$c].configuration.value);
RESULT=$(curl -s -X DELETE "$CF_URL/$ID" -H "Content-Type: application/json" -H "X-Auth-Email: $CF_AUTH_EMAIL" -H "X-Auth-Key: $CF_AUTH_KEY")
SUCCESS=$(echo $RESULT | jq -r .success)
echo -n "Deleting $IP from Cloudflare..."
echo -n $SUCCESS
echo -e ""
if [ $SUCCESS = false ]; then echo " Cloudflare Error: $(echo $RESULT | jq -r .errors[0].message)"; fi
done
echo "Bulk deletion completed!"