Skip to content

Instantly share code, notes, and snippets.

@JamesHovious
Created February 12, 2016 21:46
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 JamesHovious/1dfbc688756905c71192 to your computer and use it in GitHub Desktop.
Save JamesHovious/1dfbc688756905c71192 to your computer and use it in GitHub Desktop.
#/bin/python3
import urllib.request
import json
aws_url = "https://ip-ranges.amazonaws.com/ip-ranges.json"
aws_ips = []
with urllib.request.urlopen(aws_url) as response:
obj = json.loads(response.readall().decode('utf-8'))
for k, v in obj.items(): # type dictionary
if isinstance(v, list): # filtering on 'prefixes' which is type list
for i in v: # getting the list consists of 3 dicts
for item, value in i.items(): # parsing the keys/values of those dicts
if item == 'ip_prefix': # if they key is ip_prefix catch it
aws_ips.append(value) # append the value of ip_prefix to our empty list
print(aws_ips)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment