Skip to content

Commit 0eff024

Browse files
committed
New post: Check If an IP Address Belongs to AWS
1 parent 7285702 commit 0eff024

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
date: '2026-04-01'
3+
title: Check If an IP Address Belongs to AWS
4+
description: A quick tip to check whether an IP address belongs to AWS, including which service and region it's in.
5+
---
6+
## Check If an IP Address Belongs to AWS
7+
8+
At work, all of our services run in AWS, so when I'm looking at logs or investigating traffic I often need to know whether an IP address belongs to AWS. We do have all of our public egress IPs documented, but sometimes you just want a quick way to check an arbitrary IP without digging through internal docs. AWS publishes their complete list of IP ranges as a [public JSON file](https://ip-ranges.amazonaws.com/ip-ranges.json), and with a bit of Python you can check any IP against it in seconds.
9+
10+
```bash
11+
curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | python3 -c "
12+
import json, sys, ipaddress
13+
data = json.load(sys.stdin)
14+
targets = ['1.2.3.4', '5.6.7.8']
15+
for ip in targets:
16+
addr = ipaddress.ip_address(ip)
17+
matches = []
18+
for prefix in data['prefixes']:
19+
if addr in ipaddress.ip_network(prefix['ip_prefix']):
20+
matches.append(f\" {prefix['ip_prefix']} - {prefix['service']} ({prefix['region']})\" )
21+
if matches:
22+
print(f'{ip}: AWS IP')
23+
for m in matches:
24+
print(m)
25+
else:
26+
print(f'{ip}: NOT an AWS IP')
27+
print()
28+
"
29+
```
30+
31+
Replace the IPs in the `targets` list with whatever you want to check. For each match, it tells you which CIDR block the IP falls in, what AWS service uses it, and which region it's in. This has no dependencies beyond Python 3 and curl.

0 commit comments

Comments
 (0)