Skip to content

Instantly share code, notes, and snippets.

@ajvpot
Last active July 8, 2019 21:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajvpot/971fc97e2ae3033f0b6357f4924fe447 to your computer and use it in GitHub Desktop.
Save ajvpot/971fc97e2ae3033f0b6357f4924fe447 to your computer and use it in GitHub Desktop.
import requests
OUTFILE = "/etc/nginx/cf-access.conf"
with open(OUTFILE, 'w') as f:
f.write("# Allow CF IPv4\n")
ipv4 = requests.get("https://www.cloudflare.com/ips-v4").content.splitlines()
for line in ipv4:
f.write("allow %s;\n" % line)
f.write("\n# Allow CF IPv6\n")
ipv6 = requests.get("https://www.cloudflare.com/ips-v6").content.splitlines()
for line in ipv6:
f.write("allow %s;\n" % line)
f.write("\n# Deny all others\n")
f.write("deny all;\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment