Automatically Whitelist ManageWP IPs on Cloudflare bash Script

ManageWP is a powerful tool for managing multiple WordPress sites. It allows you to install plugins, update them, back up, monitor uptime and more without having to go into each individual WordPress site. Some hosting providers may throttle requests from ManageWP and if you are using Cloudflare and experience any blockages (for the most part I do not) you will need to whitelist the ManageWP IP addresses.

The present ManageWP IP list can be found here. Currently there are over 40 IPs which I really do not want to enter manually into Cloudflare. This script is written in bash and requires cURL and your Cloudflare API Key and email address.

Automatically Whitelist all ManageWP IPs on Cloudflare bash Script

Make sure cURL is installed, on Debian and Ubuntu you can use this command

sudo apt install curl

On CentOS

yum install curl

Create the script

sudo nano

Paste this script

# Author: Mike
# Source: WP Bullet Guides

# cloudflare email
# cloudflare API key

cd /tmp
# grab current ManageWP IP list
wget -qO /tmp/MANAGEWPTXT

# Turn text file into array

# Loop through array and add IPs to Cloudflare whitelist
# trim the \r or it breaks the JSON format
MANAGEWPIP=$(echo $MANAGEWPIP| sed "s#\r##g")
curl -s -X POST "" \
    -H "X-Auth-Email: $CFEMAIL" \
    -H "X-Auth-Key: $CFAPIKEY" \
    -H "Content-Type: application/json" \
     --data '{"mode":"whitelist","configuration":{"target":"ip","value":"'"${MANAGEWPIP}"'"},"notes":"ManageWP"}'

# delete the temporary ManageWP IPs file
rm -rf /tmp/MANAGEWPTXT



Turn File into Bash Array
Using Variables with cURL in Bash