Welcome to Centmin Mod Community
Become a Member

Install Block IP's in Cloudflare

Discussion in 'Centmin Mod User Tutorials & Guides' started by brijendrasial, Jun 14, 2023.

  1. brijendrasial

    brijendrasial Active Member

    207
    154
    43
    Mar 21, 2018
    Ratings:
    +236
    Local Time:
    6:53 PM
    1.13.9
    10.0.22-MariaDB
    Hello,

    Suppose you have 1000's of bad ips and you want to block in cloudflare then you can use below automated script.


    Code:
    #!/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="xxxxxxx@gmail.com"  # 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
     

    Attached Files: