Simple library to check if a hostname belongs to AWS IP space.
Project description
onaws
onaws
is a simple tool to check if an IP/hostname belongs to the AWS IP space or not. It uses the AWS IP address ranges data published by AWS to perform the search.
The tool could be used for:
- Continuous recon of assets
- Gathering assets using a specific service (e.g. EC2)
- Finding region information for S3 buckets
- etc.
Install
pip install onaws
Usage
Given an IP:
onaws 52.219.47.34
Given a hostname:
A domain or subdomain can be passed as input:
onaws example.com
You may also supply an S3 bucket hostname as input:
onaws dropbox.s3.amazonaws.com
Given an input list
onaws
accepts line-delimited hosts on STDIN. This is helpful if you want to pipe the output of other tools to onaws
:
$ cat hosts.txt
uber.s3.amazonaws.com
aws.com
google.com
23.21.52.140
$ cat hosts.txt | onaws
{
"is_aws_ip": true,
"ip_address": "52.218.106.162",
"service": "S3",
"region": "eu-west-1",
"matched_subnet": "52.218.0.0/17",
"hostname": "uber.s3.amazonaws.com"
}
{
"is_aws_ip": true,
"ip_address": "143.204.225.9",
"service": "CLOUDFRONT",
"region": "GLOBAL",
"matched_subnet": "143.204.0.0/16",
"hostname": "aws.com"
}
{
"is_aws_ip": false,
"ip_address": "216.58.201.238",
"hostname": "google.com"
}
{
"is_aws_ip": true,
"ip_address": "23.21.52.140",
"service": "EC2",
"region": "us-east-1",
"matched_subnet": "23.20.0.0/14"
}
Output
If the IP/hostname falls in the AWS IP range, onaws
will return the service, region and other details in the output:
{
"is_aws_ip": true,
"ip_address": "52.218.196.155",
"service": "S3",
"region": "us-west-2",
"matched_subnet": "52.218.128.0/17",
"hostname": "flaws.cloud"
}
For multiple inputs, the output format will be in JSONL:
{
"is_aws_ip": true,
"ip_address": "143.204.225.9",
"service": "CLOUDFRONT",
"region": "GLOBAL",
"matched_subnet": "143.204.0.0/16",
"hostname": "aws.com"
}
{
"is_aws_ip": false,
"ip_address": "216.58.201.238",
"hostname": "google.com"
}
{
"is_aws_ip": true,
"ip_address": "23.21.52.140",
"service": "EC2",
"region": "us-east-1",
"matched_subnet": "23.20.0.0/14"
}
Errors
If the input you provide is an invalid IP or is not resolvable, the output will indicate so:
$ onaws 'invalid.invalid'
{
"hostname": "invalid.invalid",
"resolvable": false
}
If, for some reason, the tool fails to fetch the AWS IP ranges, it will throw the following exception:
$ onaws
Failed to get AWS IP ranges
Contribution
I welcome contributions from the public. If you find something that could be improved, please file an Issue or send a PR :)
Credits
- Thanks to @TomNomNom for suggesting the name.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for onaws-0.0.14-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8ebf8af942541c0dff1b2c9dad8302324676f25f93c0ef4f6496acd5313927a |
|
MD5 | dbb08cfcfac72e61d0f7178fd241e716 |
|
BLAKE2b-256 | 484ef60300f84a501ad9667d50b23e7365f9c2c8016ccb29dc711ca85bcf872a |