Skip to content

Instantly share code, notes, and snippets.

@supersonictw
Last active December 12, 2024 08:38
Show Gist options
  • Save supersonictw/2d19d98da8a4845c22c7cadb7ea02d38 to your computer and use it in GitHub Desktop.
Save supersonictw/2d19d98da8a4845c22c7cadb7ea02d38 to your computer and use it in GitHub Desktop.
#!/bin/bash
# cloudflare_nginx_ip.sh
# SPDX-License-Identifier: MIT (https://ncurl.xyz/s/o_o6DVqIR)
# https://gist.github.com/supersonictw/2d19d98da8a4845c22c7cadb7ea02d38
# crontab -e
# 0 3 * * * /somewhere/cloudflare_nginx_ip.sh # update at 3 a.m every day
set -e
WORKPLACE="/opt/cloudflare"
GET_IP_LIST() {
for type in v4 v6; do
curl -sfSL "https://www.cloudflare.com/ips-$type"
echo
done
}
mkdir -p "$WORKPLACE"
IP_LIST="$(GET_IP_LIST)"
echo "$IP_LIST" | sed "s|^|allow |g" | sed "s|\$|;|g" >"$WORKPLACE/ip_allowed.txt"
echo "$IP_LIST" | sed "s|^|set_real_ip_from |g" | sed "s|\$|;|g" >"$WORKPLACE/ip_realip.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment