Hello,
I have written a small program to block bad ips in cloudflare. Suppose you have 1000's of ips and you want to block it you can use below program.
I have written a small program to block bad ips in cloudflare. Suppose you have 1000's of ips and you want to block it you can use below program.
Cod:
#!/bin/sh
# Block IP in Cloudflare from file list
GLOBAL_API_KEY="xxxxxxxx" # Global api key can be obtained from here https://dash.cloudflare.com/profile/api-tokens
ACCOUNTS_EMAIL="[email protected]" # Email address of your cloudflare account
IPLIST="./ips.txt" # Create ips.txt in same folder of software
MODES="challenge" # challenge, block, js_challenge, managed_challenge
NOTES="ddos`date +"%Y%m%d"`"
while read host; do
HOSTIP=($host)
curl -X POST "https://api.cloudflare.com/client/v4/user/firewall/access_rules/rules" -H "X-Auth-Key:${GLOBAL_API_KEY}" -H "X-Auth-Email:${ACCOUNTS_EMAIL}" -H "Content-Type:application/json" --data "{\"mode\":\"${MODES}\",\"configuration\":{\"target\":\"ip\",\"value\":\"${HOSTIP[0]}\"},\"notes\":\"${NOTES}\"}"
done < $IPLIST