Skip to content

Commit a869723

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

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
Add this function to your `~/.bashrc` or `~/.zshrc`:
11+
12+
```bash
13+
awsip() {
14+
curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | python3 -c "
15+
import json, sys, ipaddress
16+
data = json.load(sys.stdin)
17+
for ip in sys.argv[1:]:
18+
addr = ipaddress.ip_address(ip)
19+
matches = [f' {p[\"ip_prefix\"]} - {p[\"service\"]} ({p[\"region\"]})' for p in data['prefixes'] if addr in ipaddress.ip_network(p['ip_prefix'])]
20+
print(f'{ip}: AWS IP' if matches else f'{ip}: NOT an AWS IP')
21+
for m in matches: print(m)
22+
print()
23+
" "$@"
24+
}
25+
```
26+
27+
Then you can just run `awsip 1.2.3.4 5.6.7.8` from your terminal. 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)