Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<img src="img/gcp-ip-addresses.png" width="32%"></img>
<img src="img/azure-ip-addresses.png" width="32%"></img>

`aws_region_ip_sizes.py` fetches AWS `ip-ranges.json`, collapses overlapping IPv4 CIDRs, and prints unique IP counts by region.

# [compute / memory unit prices by virtual machine type](https://instances.vantage.sh/)
<img src="img/ec2-unit-prices.png" width="100%"></img>
<img src="img/gcp-unit-prices.png" width="49%"></img>
Expand Down
39 changes: 39 additions & 0 deletions aws_region_ip_sizes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3
from collections import defaultdict
from ipaddress import collapse_addresses, ip_network
from json import load
from urllib.request import urlopen


AWS_IP_RANGES_URL = "https://ip-ranges.amazonaws.com/ip-ranges.json"


def load_aws_prefixes(url=AWS_IP_RANGES_URL):
with urlopen(url) as response:
return load(response)["prefixes"]


def unique_ipv4_counts_by_region(prefixes):
regions = defaultdict(list)
for prefix in prefixes:
if "ip_prefix" not in prefix:
continue
regions[prefix["region"]].append(ip_network(prefix["ip_prefix"]))

return {
region: sum(network.num_addresses for network in collapse_addresses(networks))
for region, networks in regions.items()
}


def main():
counts = unique_ipv4_counts_by_region(load_aws_prefixes())
total = sum(counts.values())

for region, count in sorted(counts.items(), key=lambda item: item[1], reverse=True):
print(f"{region}: {count / total:.2%} ({count:,})")
print(f"total: {total // 1_000_000} million")


if __name__ == "__main__":
main()