GithubHelp home page GithubHelp logo

eitrtechnologies / subnet_gap_finder Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 0.0 11 KB

Utility script to show unused gaps in IP space within a list of networks

License: Apache License 2.0

Python 100.00%
vpc subnets networking aws aws-networking

subnet_gap_finder's Introduction

Subnet Gap Finder

Utility script to show unused gaps in IP space within a list of networks.

Background

This script was born out of a need to find unused subnet space within a large, micro-segmented VPC in AWS. Sorting the subnets and looking for spaces manually isn't easy on the eyes. The first iteration of this script used a file input which was accomplished by copying and pasting subnets out of the AWS UI and then massaging the data to remove the extra information. Once I proved that the logic worked, I added the functionality necessary to get the subnet information straight from the source. I hope you find it useful.

Usage

The script takes either the filename or the vpcid argument... not both.

usage: subnet_gap_finder.py [-h] [--filename FILENAME] [--loglevel LOGLEVEL]
                            [--vpcid VPC_ID]

Utility script to show unused gaps in IP space within a list of networks.

optional arguments:
  -h, --help            show this help message and exit
  --filename FILENAME, -f FILENAME
                        Path to a file containing a list of IP networks.
                        EITHER "filename" OR "vpcid" IS REQUIRED
  --loglevel LOGLEVEL, -l LOGLEVEL
                        Specify log level as text string: ERROR, WARNING,
                        INFO, DEBUG
  --vpcid VPC_ID, -i VPC_ID
                        ID of a VPC in AWS to query. Subnets will be checked
                        as the list of networks. EITHER "filename" OR "vpcid"
                        IS REQUIRED.

File input

File input expects a newline-separated list of subnets in the file. Any line containing other text is thrown out, so you don't need to clean up your data too much.

$ python3 subnet_gap_finder.py --filename tests/example.txt
| Gap Start   | Gap End    | Gap CIDRs     |
|-------------+------------+---------------|
| 10.0.6.128  | 10.0.6.255 | 10.0.6.128/25 |
| 10.0.7.32   | 10.0.7.63  | 10.0.7.32/27  |
| 10.0.7.128  | 10.0.7.159 | 10.0.7.128/27 |

VPC ID

VPC mode basically works the same way, with the exception that we can also see unused space at the end of the last subnet until the end of the VPC address space. This is (currently) only shown if there aren't any gaps between subnets.

NOTE: We're not handling AWS authentication in the script. Ensure that you authenticate via the AWS CLI prior to running.

$ python3 subnet_gap_finder.py --vpcid vpc-a675b09
| Gap Start   | Gap End     | Gap CIDRs     |
|-------------+-------------+---------------|
| 10.0.8.0    | 10.0.15.255 | 10.0.8.0/21   |

subnet_gap_finder's People

Contributors

nicholasmhughes avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.