Skip to main content

Get the Cloud Provider netblocks (Python3 version)

Project description

Netblocks

This is not an official Google product.

This is a Google App Engine app that regularly checks the DNS entries using the netblocks module. This App engine code updates the GCS bucket, when there is a change in the CIDR blocks for GCE.

The netblocks api module itself can be used outside App Engine. Install the package with pip install netblocks or pip install git+https://github.com/hm-distro/netblocks/

Downstream systems can hook into the Object notification on the GCS bucket and accordingly do something with the file, with the updated CIDR ranges. The schedule of this refresh can be managed in the cron.yaml and the bucket and file where the CIDR ranges should be written to can be changed in the config.py

Potential listeners could be Cloud Functions.

API Usage

import netblocks
cidr_blocks = set()
netblocks_api = netblocks.NetBlocks()
try:
    cidr_blocks = netblocks_api.fetch()
    
    """
    The cidr_blocks set contains strings like the below
    ip4:146.148.2.0/23
    ...
    ip6:2600:1900::/35
    """
    
except netblocks.NetBlockRetrievalException as err:
    #exception handling
    pass

The GAE App

  • UpdateGCSBucket

This class creates a file in the GCS bucket as specified in config.py.
The files contains entries such as the below:
ip4:146.148.2.0/23
...
ip6:2600:1900::/35
Make sure to create a bucket prior to deploying the app
This bucket-name should be changed in the config.py under GCS_BUCKET

Deploy using

gcloud app deploy app.yaml

gcloud app deploy cron.yaml

Products

Language

Dependencies

Run these steps before deploying the app
mkdir lib
pip install -t ./lib/ google-api-python-client
pip install -t ./lib/ GoogleAppEngineCloudStorageClient
pip install -t ./lib/ requests
pip install -t ./lib/ oauth2client
pip install -t ./lib/ requests-toolbelt

License

Apache 2.0; see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for netblocks3, version 0.0.13
Filename, size File type Python version Upload date Hashes
Filename, size netblocks3-0.0.13-py3-none-any.whl (14.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size netblocks3-0.0.13.tar.gz (9.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page