Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save dylanmtaylor/b47a26f708814bf9544dc77e16c4d82f to your computer and use it in GitHub Desktop.

Select an option

Save dylanmtaylor/b47a26f708814bf9544dc77e16c4d82f to your computer and use it in GitHub Desktop.
Check if IP is an AWS IP
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