Demo entry 6783650

for network admins to design VLSM subneting


Submitted by Scottie on Feb 17, 2019 at 10:04
Language: Python 3. Code size: 2.4 kB.

import ipaddress

#This is sample program designed to design VLSM subneting
#This is version 3.  In this version, instead of storing data in multidimantion arrays
#I will using dictionaries instead
#This version will also use more functions to make the code look cleaner

def display_menu(subnet_count):
    dash= "*"*30
    print("Use this program to calculate variable length subnetting")
    #print("In this version, we will only take class C addresses")
def ask_count():
    subnet_count= int(input ("Please enter the number of desired subnets: "))
    print("You wanted " + str(subnet_count) + " subnets")
    return subnet_count

def ask_address():
    address = input("Please enter your network address: ")
    ip_add = ipaddress.ip_address(address)

def add_list_and_subnet(vlsm_list):
    name= input("Please enter the name of this subnet: ")
    name = name.title()
    vlan= int(input("Please enter the amount of host needed for your next subnet: "))
    while ((vlan >254 or vlan <= 1)):
        vlan = int(input("Please enter vlan size between 1 and 254: "))

    print(name, 'needed ', vlan, 'hosts')

    vlsm_list[name] = subnetted(vlan)

def subnetted(hosts):
    Take amount of hosts as input and return the smallest size of vlan
    that can be used for this subnet
    vlan = 2**0

    while (vlan-1) < hosts:
        vlan = vlan*2

    return vlan

def sort_vlsm(vlsm_list):
    temp = sorted(vlsm_list.items(), key=lambda x:x[1], reverse = True)
    vlsm_list = dict(temp)
def show_result(vlsm_list, ip_add):
    for key, value in vlsm_list.items():
        print('Subnet ', key, ' has network address of ', ip_add,
              '\nwith host addresses from ', ip_add+1, 'to ',ip_add+ vlsm_list[key]-2
              ,'\nwith broadcast address: ', ip_add+vlsm_list[key]-1)
        ip_add = ip_add + int(value)
def main():
    subnet_count = 0
    vlsm_list = {}
    subnet_count = ask_count()
    ip_add = ask_address()
    for i in range(0,subnet_count):

    show_result(vlsm_list, ip_add)
if __name__ == "__main__":

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).