Reputation: 15513
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?
Upvotes: 4
Views: 5162
Reputation: 52393
Download the JSON file AWS IP ranges: AWS IP Address Ranges
It contains the CIDR
s. You may want to write a simple script and check if the IP falls in any of the CIDR
s 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'
Upvotes: 11