Skip to content

Instantly share code, notes, and snippets.

@philipithomas
Last active May 17, 2017 15:40
Show Gist options
  • Save philipithomas/9662726968cc6033b4d2 to your computer and use it in GitHub Desktop.
Save philipithomas/9662726968cc6033b4d2 to your computer and use it in GitHub Desktop.
Whitelist AWS Health Check IPs in Cloudflare
import requests
import netaddr
ranges = [
"54.183.255.128/26",
"54.228.16.0/26",
"54.232.40.64/26",
"54.241.32.64/26",
"54.243.31.192/26",
"54.244.52.192/26",
"54.245.168.0/26",
"54.248.220.0/26",
"54.250.253.192/26",
"54.251.31.128/26",
"54.252.254.192/26",
"54.252.79.128/26",
"54.255.254.192/26",
"107.23.255.0/26",
"176.34.159.192/26",
"177.71.207.128/26",
]
url = "https://www.cloudflare.com/api_json.html"
for cidr_range in ranges:
for ip in netaddr.IPNetwork(cidr_range):
# Unpack each range. Note that a /26 is 64 ips.
payload = {
"a": "wl",
"tkn": "",
"email": "",
"key": ip,
}
r = requests.post(url, data=payload).json()
if r.get("result") == "success":
print("whitelisted {}".format(ip))
else:
print("Error with ip {}".format(ip))
print(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment