I am trying to determine the AWS Region that my heroku database is stored on. All I have is the IP address.
How can i determine the AWS region?
Download the JSON file AWS IP ranges: AWS IP Address Ranges
It contains the CIDRs. You may want to write a simple script and check if the IP falls in any of the CIDRs and then retrieve the corresponding region. This is how JSON looks:
{
"ip_prefix": "13.56.0.0/16",
"region": "us-west-1",
"service": "AMAZON"
},
Here is Python3 code to find the region, given an IP. Assumes the ip-ranges.json file downloaded from AWS is in the current directory. Will not work in Python 2.7
from ipaddress import ip_network, ip_address
import json
def find_aws_region(ip):
ip_json = json.load(open('ip-ranges.json'))
prefixes = ip_json['prefixes']
my_ip = ip_address(ip)
region = 'Unknown'
for prefix in prefixes:
if my_ip in ip_network(prefix['ip_prefix']):
region = prefix['region']
break
return region
Test
>>> find_aws_region('54.153.41.72')
'us-west-1'
>>> find_aws_region('54.250.58.207')
'ap-northeast-1'
>>> find_aws_region('154.250.58.207')
'Unknown'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With