Created
February 12, 2016 21:46
-
-
Save JamesHovious/1dfbc688756905c71192 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/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