This script assigns subnets to requested networks based on a base CIDR network. The assigned subnets are non-overlapping and cover the entire base CIDR network.
- Python 3.6 or higher
ipaddressmodule (included in Python 3)jsonmodule (included in Python 3)argparsemodule (included in Python 3)csvmodule (included in Python 3)
python subnetting.py -s BASE_CIDR -j JSON_FILE -l LOCATION_CODE -c COMPANY_NAME-s,--base-cidr: the base CIDR network to use (required)-j,--json-file: the JSON file containing the network definitions (either JSON or YAML required)-y,--yaml-file: the JSON file containing the network definitions (either JSON or YAML required)-l,--location-code: a 3-character location code to use in network descriptions (required)-c,--company-name: the company name to use in network descriptions (required)-o,--output-csv: save the output as csv (optional)
The JSON file should be an array of network objects, where each object has the following properties:
name: the name of the networkcidr: the size of the network in CIDR notation (e.g.22)vid: the VLAN ID to use for the network
Example JSON file:
[
{
"name": "server",
"cidr": 22,
"vid": 2000
},
{
"name": "clients",
"cidr": 22,
"vid": 2010
},
{
"name": "guest-wifi",
"cidr": 23,
"vid": 2021
}
]The JSON/YAML file should be an array of network objects, where each object has the following properties:
name: the name of the networkcidr: the size of the network in CIDR notation (e.g.22)vid: the VLAN ID to use for the network
Example YAML file:
- name: server
cidr: 22
vid: 2000
- name: clients
cidr: 22
vid: 2010
- name: guest-wifi
cidr: 23
vid: 2021The script outputs the assigned subnets for each network in the following format:
192.0.1.0/22 clients (My Company - server)
192.0.2.0/22 server (My Company - clients)
192.0.3.0/23 guest (My Company - guest-wifi)
The network description includes the company name and location code.
If provided, the output is saved to a csv file.
# Assign subnets of the base network 10.10.0.0/19
subnetting.py -s 192.0.2.0/24 -j net_definitions.json -l MUC -c MyCompany
# Assign subnets of the base network 10.10.0.0/19 and save the output to the csv file
subnetting.py -s 192.0.2.0/24 -j net_definitions.json -l MUC -c MyCompany -o subnets.csvThis project is licensed under the terms of the MIT license.