Skip to content

Instantly share code, notes, and snippets.

@torian
Created August 5, 2019 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torian/c4a6c1e9bbe049ddb911b7a860ed5359 to your computer and use it in GitHub Desktop.
Save torian/c4a6c1e9bbe049ddb911b7a860ed5359 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os
import requests
import json
AWS_SERVICE = os.environ.get("AWS_SERVICE", "CLOUDFRONT")
AWS_IP_RANGES = "https://ip-ranges.amazonaws.com/ip-ranges.json"
req = requests.get(AWS_IP_RANGES).text
ip_ranges = json.loads(req)
cf_service = filter(lambda i: i['service'] == AWS_SERVICE, ip_ranges['prefixes'])
cf_ips = map(lambda j: j['ip_prefix'], cf_service)
for ip in cf_ips:
print ip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment