Instantly share code, notes, and snippets.

@ajvpot /cfupdate.py Secret
Last active Jun 18, 2016

Embed
What would you like to do?
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