i’ve written some code here to essentially take user input and then give back the subnet range, any pointers and thoughts would be appreciated!
i would also like to split it so that each pair of numbers is it’s own separate list within the list “subnet_ranges”
number = int(input("which variable would you like to use to find the subnet ranges for this network? press 1 for the amount of subnets, 2 for the amount of hosts, 3 for the CIDR (the / after the ip address), and press 4 for the third octet of the subnet mask. (octets are the numbers before each dot)"))
number_wanted = int(input("great! what's the number of the variable you want?"))
index_wanted = number-1
#the numbers represent, in order: subnets, hosts, CIDR, subnet mask 3rd octet.
different_types = [[1, 256, 24, 255], [2, 128, 25, 128], [4, 64, 26, 192], [8, 32, 27, 224], [16, 16, 28, 240],[32, 8, 29, 248], [64, 4, 30, 252], [128, 2, 31, 254]]
wanted = []
for i in different_types:
if i[index_wanted] == number_wanted:
wanted.append(i)
subnet_ranges = list(range(0, 257, wanted[0][1]))
print(subnet_ranges)
as a side thing some of the variables near the beginning don’t really sit right with me so suggestions about what to change them to would be appreciated as well!