subnetting

Advanced IPv4 Subnet Calculator in Python3.

Getting Started

│   main.py
│   read_subnets.py
│   subnetting.py
│   export_subnets.py
│   parse_excel.py
│   svi_generator.py
│   svi.j2
│   subnets.csv
│   requirements.txt
│   README.md
│   .pre-commit-config.yaml
│   .gitignore
│   LICENSE
│
└───assets
        preview.png
        subnets-csv.png
        subnetting-cli.png
        svi.png

Installation

$ git clone https://github.com/Tes3awy/subnetting.git
$ cd subnetting
$ pip install -r requirements.txt --user

OR

  1. Download latest release from Releases.
  2. Extract subnetting-<ver>.zip file.
  3. cd into subnetting-<ver> directory.
  4. Run path_to\subnetting-<ver>> pip install -r requirements.txt --user in terminal.

How it works?

Windows

path_to\subnetting> python main.py

macOS or Linux

$ python3 main.py

You will be prompted to enter the name of the CSV file containing input subnets, the gateway IP address, a name for the Excel file to be created, and the name of the sheet within the Excel file that will hold all subnetting data. (All inputs have default values).

A subnets.csv file can be found in the repo. This file is an entry point to get started using this program. It's prepopulated with three different subnets. (Class A, Class B, and Class C).

- CSV file w/ extension? [Defaults to subnets.csv]:
- Gateway first or last IP Address? [0/1] [Defaults to 0]:
- Excel file w/o extension? [Defaults to IP-Schema]: Test-Schema
- Worksheet name? [Defaults to IP Schema Worksheet]: Test Worksheet
  • Abbreviations:
    - w/: With
    - w/o: Without

Voila :sparkles: You have an Excel file that includes all required data about each subnet.

Please check Test-Schema_<TODAYS_DATE>.xlsx in current working directory.

Default behaviors:

  1. CIDR notation with no prefix length will be handled as /32.
    - For example, if you enter 10.0.0.0 without a prefix length in the CSV file, the script will handle it like 10.0.0.0/32.
  1. The header line Subnets in CIDR Notation within the subnets.csv file is automatically skipped. So, there is no need to manually remove it.
  1. Gateway input accepts 0 or 1 ONLY [Defaults to 0]. 0 picks the first IP address of the subnet, while 1 picks the last IP address.
  1. Microsoft Excel does not allow worksheet name longer than 31 characters. Worksheet names longer than 31 chars will be truncated.

SVI Configuration Template

Finally, if you have a L3 switch and you want to create SVI interfaces of the created subnets on that switch, you can run:

$ python parse_excel.py --file Test-Schema-<TODAYS_DATE>.xlsx

This Python script will generate a text file including all VLANs and their SVI interfaces.

NOTE: Make sure you add the VLAN ID and VLAN Name in all the cells in the generated Excel file before running this script. Otherwise, VLAN ID and VLAN Name will be NaN in the generated text file.


Previews

Terminal
subnetting-cli

CSV File (Input File)
subnets-csv

Excel File (Output File)
preview

SVI Template
svi

GitHub

https://github.com/Tes3awy/subnetting