Skip to content

Instantly share code, notes, and snippets.

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