This post explains how to get current IP address ranges used by AWS services using Python.
AWS publishes its IP ranges in .json
file that can be downloaded from here.
import json
import requests
json
file content using requests.get
aws_ip_ranges_url = "https://ip-ranges.amazonaws.com/ip-ranges.json"
aws_ip_ranges = json.loads(requests.get(aws_ip_ranges_url).text)
for ip_range in aws_ip_ranges["prefixes"]:
if ip_range["service"] == "S3":
print(ip_range["service"], ip_range["ip_prefix"], ip_range["region"])
for ip_range in aws_ip_ranges["prefixes"]:
if ip_range["service"] == "CLOUDFRONT":
print(ip_range["service"], ip_range["ip_prefix"], ip_range["region"])
for ip_range in aws_ip_ranges["prefixes"]:
if ip_range["service"] == "ROUTE53_HEALTHCHECKS":
print(ip_range["service"], ip_range["ip_prefix"], ip_range["region"])
for ip_range in aws_ip_ranges["prefixes"]:
if ip_range["service"] == "AMAZON_APPFLOW":
print(ip_range["service"], ip_range["ip_prefix"], ip_range["region"])
for ip_range in aws_ip_ranges["prefixes"]:
if ip_range["service"] == "KINESIS_VIDEO_STREAMS":
print(ip_range["service"], ip_range["ip_prefix"], ip_range["region"])
import json
import requests
aws_ip_ranges_url = "https://ip-ranges.amazonaws.com/ip-ranges.json"
aws_ip_ranges = json.loads(requests.get(aws_ip_ranges_url).text)
for ip_range in aws_ip_ranges["prefixes"]:
if ip_range["service"] == "S3":
print(ip_range["service"], ip_range["ip_prefix"], ip_range["region"])
for ip_range in aws_ip_ranges["prefixes"]:
if ip_range["service"] == "CLOUDFRONT":
print(ip_range["service"], ip_range["ip_prefix"], ip_range["region"])
for ip_range in aws_ip_ranges["prefixes"]:
if ip_range["service"] == "ROUTE53_HEALTHCHECKS":
print(ip_range["service"], ip_range["ip_prefix"], ip_range["region"])
for ip_range in aws_ip_ranges["prefixes"]:
if ip_range["service"] == "AMAZON_APPFLOW":
print(ip_range["service"], ip_range["ip_prefix"], ip_range["region"])
for ip_range in aws_ip_ranges["prefixes"]:
if ip_range["service"] == "KINESIS_VIDEO_STREAMS":
print(ip_range["service"], ip_range["ip_prefix"], ip_range["region"])
Category: AWS