Skip to content

Instantly share code, notes, and snippets.

Forked from LyftGalactic/
Created November 7, 2019 18:21
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
A quick script to determine AWS Region from IP Address
from ipaddress import ip_network, ip_address
import json
import requests
import sys
def find_aws_region():
ip_json = requests.get('')
#ip_json = json.load(open('ip-ranges.json'))
ip_json = ip_json.json()
prefixes = ip_json['prefixes']
my_ip = ip_address(sys.argv[1])
region = 'Unknown'
for prefix in prefixes:
if my_ip in ip_network(prefix['ip_prefix']):
region = prefix['region']
return region
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment