Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import urllib.request
import json
aws_url = ""
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment