Skip to content

Instantly share code, notes, and snippets.

@nobiit
Created January 15, 2025 15:22
Show Gist options
  • Select an option

  • Save nobiit/e7ce4cdd65a73ebbd98725efe25313e0 to your computer and use it in GitHub Desktop.

Select an option

Save nobiit/e7ce4cdd65a73ebbd98725efe25313e0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
ip_ranges="$(curl -fsL https://ip-ranges.amazonaws.com/ip-ranges.json | jq -r '.prefixes')"
python3 - "${1}" <<-EOF
from sys import stdin, argv
from ipaddress import ip_address, ip_network
for network in $(echo "${ip_ranges}" | jq -r 'tojson'):
if ip_address(argv[1]) in ip_network(network["ip_prefix"]):
print(network)
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment