Skip to main content

Work with the AWS IP address ranges in native Python.

Project description

awsipranges

Work with the AWS IP address ranges in native Python.

License PyPI Code Coverage Build Docs


Amazon Web Services (AWS) publishes its current IP address ranges in JSON format. Python v3 provides an ipaddress module in the standard library that allows you to create, manipulate, and perform operations on IPv4 and IPv6 addresses and networks. Wouldn't it be nice if you could work with the AWS IP address ranges like native Python objects?

Features

  • Work with the AWS IP prefixes as a simple AWSIPPrefixes collection.
  • Quickly check if an IP address, interface, or network is contained in the AWS IP address ranges.
  • Get the AWS IP prefix that contains an IP address, interface, or network.
  • See what services are served from an IP prefix.
  • Filter the AWS IP prefixes by region, network border group, service, and IP prefix version.
  • Use the AWS prefix data in your app or automation scripts in the format required by your infrastructure.
  • Easily validate the TLS certificate presented by the IP ranges server.
  • awsipranges has no third-party dependencies and is compatible with CPython v3.7+.
>>> import awsipranges

>>> aws_ip_ranges = awsipranges.get_ranges(cafile="amazon_root_certificates.pem")

>>> '52.94.5.15' in aws_ip_ranges
True

>>> aws_ip_ranges['52.94.5.15']
AWSIPv4Prefix('52.94.5.0/24', region='eu-west-1', network_border_group='eu-west-1', services=('AMAZON', 'DYNAMODB'))

>>> aws_ip_ranges.filter(services='CODEBUILD')
{'create_date': datetime.datetime(2021, 8, 24, 1, 31, 14, tzinfo=datetime.timezone.utc),
 'ipv4_prefixes': (AWSIPv4Prefix('3.26.127.24/29', region='ap-southeast-2', network_border_group='ap-southeast-2', services=('CODEBUILD',)),
                   AWSIPv4Prefix('3.38.90.8/29', region='ap-northeast-2', network_border_group='ap-northeast-2', services=('CODEBUILD',)),
                   AWSIPv4Prefix('3.68.251.232/29', region='eu-central-1', network_border_group='eu-central-1', services=('CODEBUILD',)),
                   AWSIPv4Prefix('3.98.171.224/29', region='ca-central-1', network_border_group='ca-central-1', services=('CODEBUILD',)),
                   AWSIPv4Prefix('3.101.177.48/29', region='us-west-1', network_border_group='us-west-1', services=('CODEBUILD',)),
                   ...),
 'ipv6_prefixes': (),
 'sync_token': '1629768674'}

>>> for prefix in aws_ip_ranges.filter(regions='eu-west-1', services='DYNAMODB'):
...     print(prefix.network_address, prefix.netmask)
...
52.94.5.0 255.255.255.0
52.94.24.0 255.255.254.0
52.94.26.0 255.255.254.0
52.119.240.0 255.255.248.0

Installation

Installing and upgrading awsipranges is easy:

Install via PIP

 pip install awsipranges

Upgrade to the latest version

 pip install --upgrade awsipranges

Documentation

Excellent documentation is now available at: https://aws-samples.github.io/awsipranges/

Check out the Quickstart to dive in and begin using awsipranges.

Contribute

See CONTRIBUTING for information on how to contribute to this project.

Security

See CONTRIBUTING for information on how to report a security issue with this project.

License

This project is licensed under the Apache-2.0 License.

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

awsipranges-0.3.3.tar.gz (16.7 kB view hashes)

Uploaded Source

Built Distribution

awsipranges-0.3.3-py3-none-any.whl (18.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page