Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ccharlton/216dd8280e8449a9c3ac460a91c682d0 to your computer and use it in GitHub Desktop.
Save ccharlton/216dd8280e8449a9c3ac460a91c682d0 to your computer and use it in GitHub Desktop.
Cloudflare firewall bulk IP whitelist
#!/bin/bash
IPADDRESS=("123.123.123.124" "456.456.456.457" "890.890.890.891")
echo "Adding IP addresses to Cloudflare Firewall..."
echo ''
for i in "${IPADDRESS[@]}"
do
:
# do whatever on $i
echo $i
curl -X POST "https://api.cloudflare.com/client/v4/user/firewall/access_rules/rules" \
-H "X-Auth-Email: [email protected]" \
-H "X-Auth-Key: YOURPRIVATECLOUDFLAREAPIKEY" \
-H "Content-Type: application/json" \
--data '{"mode":"whitelist","configuration":{"target":"ip","value":"'$i'"},"notes":"Why this IP was added"}'
echo ''
done
echo ''
echo "Done adding IP addresses to Cloudflare Firewall"
@junneshenning
Copy link

You need to run this shell script with bash command, not sh command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment