Created
June 24, 2019 22:03
-
-
Save louiszuckerman/d2cd2bf3b7a4d12dc84b6de07bf960f9 to your computer and use it in GitHub Desktop.
list all of the IPv4 addresses in an AWS region and provide a summary count
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
""" | |
List & count all IPv4 addresses in an AWS region | |
""" | |
import requests | |
REGION = 'us-east-1' | |
rsp = requests.get('https://ip-ranges.amazonaws.com/ip-ranges.json') | |
rj = rsp.json() | |
print("Here are all of the IPv4 netblocks in %s" % REGION) | |
acc = 0 | |
for i in rj['prefixes']: | |
if i.get('ip_prefix') and i['region'] == REGION: | |
range = i['ip_prefix'] | |
print(range) | |
acc += 2 ** (32 - int(range[range.index('/')+1:])) | |
print("These cover a total of %s IP addresses" % acc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment