Created
July 11, 2024 08:05
-
-
Save presswizards/67978a143936503f0589d00229cc2fac to your computer and use it in GitHub Desktop.
Plesk Add Trusted IPs to fail2ban to prevent badbot blocks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# add to crontab to run once per day or week like so via "crontab -e": | |
# 0 0 */1 * * ~/add_trusted_ips.sh > /dev/null | |
# URL containing the list of trusted IPs | |
URL1="https://optimize.exactlywww.com/exactdn/servers.php" | |
URL2="https://www.cloudflare.com/ips-v4/" | |
URL3="https://www.cloudflare.com/ips-v6/" | |
URL4="https://api.bunny.net/system/edgeserverlist/plain" | |
# Fetch the list of IPs from the URLs | |
ips1=$(curl -s $URL1) | |
ips2=$(curl -s $URL2) | |
ips3=$(curl -s $URL3) | |
ips4=$(curl -s $URL4) | |
# Convert the list of IPs from newline-delimited to semicolon-delimited | |
trusted_ips1=$(echo "$ips1" | tr '\n' ';') | |
trusted_ips2=$(echo "$ips2" | tr '\n' ';') | |
trusted_ips3=$(echo "$ips3" | tr '\n' ';') | |
trusted_ips4=$(echo "$ips4" | tr -d '\r' | tr '\n' ';') | |
# Remove the old IPs from the Plesk trusted list to prevent duplicates | |
sudo plesk bin ip_ban --remove-trusted "$trusted_ips1" | |
sudo plesk bin ip_ban --remove-trusted "$trusted_ips2" | |
sudo plesk bin ip_ban --remove-trusted "$trusted_ips3" | |
sudo plesk bin ip_ban --remove-trusted "$trusted_ips4" | |
# Add the fresh IPs to the Plesk trusted list with descriptions | |
sudo plesk bin ip_ban --add-trusted "$trusted_ips1" -description "ExactDN" | |
sudo plesk bin ip_ban --add-trusted "$trusted_ips2" -description "CloudflareIPv4" | |
sudo plesk bin ip_ban --add-trusted "$trusted_ips3" -description "CloudflareIPv6" | |
sudo plesk bin ip_ban --add-trusted "$trusted_ips4" -description "BunnyCDN" |
Add support for other server and home/office IPs, if exists in a local file, or just hardcoded...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add support for:
Site24x7 Uptime IPs (Seattle WA): (https://www.site24x7.com/multi-location-web-site-monitoring.html)
ManageWP IPs: (https://managewp.com/troubleshooting/general/managewp-ips-can-white-list)