Created
April 1, 2026 18:18
-
-
Save dylanmtaylor/b47a26f708814bf9544dc77e16c4d82f to your computer and use it in GitHub Desktop.
Check if IP is an AWS IP
This file contains hidden or 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
| curl -s https://ip-ranges.amazonaws.com/ip-ranges.json | python3 -c " | |
| import json, sys, ipaddress | |
| data = json.load(sys.stdin) | |
| targets = ['1.2.3.4'] | |
| for ip in targets: | |
| addr = ipaddress.ip_address(ip) | |
| matches = [] | |
| for prefix in data['prefixes']: | |
| if addr in ipaddress.ip_network(prefix['ip_prefix']): | |
| matches.append(f\" {prefix['ip_prefix']} - {prefix['service']} ({prefix['region']})\" ) | |
| if matches: | |
| print(f'{ip}: AWS IP') | |
| for m in matches: | |
| print(m) | |
| else: | |
| print(f'{ip}: NOT an AWS IP') | |
| print() | |
| " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment