-
Notifications
You must be signed in to change notification settings - Fork 0
/
6_ipdesign.py
64 lines (44 loc) · 1.87 KB
/
6_ipdesign.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import ipaddress
import math
startip = input("Enter the starting IP Address: ")
cidr = int(input("Enter the CIDR value: "))
n = int(input("Enter the no. of groups: "))
customers = []
allocated = 0
for i in range(n):
x = int(input("Group " + str(i+1) + ": "))
customers.append(x)
allocated = allocated + x
def get_ip_range(startip, customers, gropuno):
ip = ipaddress.ip_address(startip)
start = ip
end = ip + customers[gropuno]
return start, end
def get_count(startip, cidr):
ip = ipaddress.ip_network(startip + "/" + str(cidr), strict=False)
total = ip.num_addresses
remaining = total - allocated
return total, allocated, remaining
print("*****************************************************************")
groups = 0
while groups < n:
subgroup = []
x = int(input("Enter the no. of subgroups in group " + str(groups+1) + ": "))
for i in range(x):
subgroup.append(int(input("Enter no. of customers in subgroup " + str(i+1) + ": ")))
print("---------------------- Group " + str(groups + 1) + " ----------------------")
for i in range(x):
start, end = get_ip_range(startip, subgroup, i)
rcidr = 32 - int(math.log2(subgroup[i]))
subnet = ipaddress.ip_network(str(start)+"/"+str(rcidr), strict=False).netmask
print("IP range for the subgroup " + str(i+1) + "----------> " + str(start) + " - " + str(end - 1))
print("CIDR value: " + str(rcidr))
print("Subnet mask: " + str(subnet))
print("-------------------------------------------------------")
startip = str(end)
groups = groups + 1
print("*****************************************************************")
total, alloted, remaining = get_count(startip,cidr)
print("Total IP addresses: " + str(total))
print("Alloted IP addresses: " + str(alloted))
print("Remaining IP addresses: " + str(remaining))