Complete the code to calculate the number of hosts in a subnet given the subnet mask bits.
hosts = (2 ** (32 - [1])) - 2
The subnet mask bits represent the network portion. Subtracting from 32 gives the host bits. The number of hosts is 2 to the power of host bits minus 2 (for network and broadcast addresses).
Complete the code to find the subnet mask in dotted decimal notation from the number of mask bits.
mask = [[1] for i in range(4)]
Each full byte in the subnet mask is 255 in decimal. For example, a /24 mask has three full bytes of 255.
Fix the error in the code to calculate the number of subnets given the borrowed bits.
subnets = 2 ** [1]
The number of subnets is 2 raised to the power of the number of bits borrowed from the host portion.
Fill both blanks to create a dictionary comprehension that maps subnet numbers to their subnet masks in binary.
subnet_masks = {n: bin(255 << (8 - [1])) for n in range([2])}The subnet mask for each subnet is calculated by shifting 255 left by (8 - borrowed_bits). The range is the number of subnets.
Fill all three blanks to create a dictionary comprehension that maps subnet numbers to their broadcast addresses.
broadcasts = {n: network_base + ([1] * n) + [2] for n in range([3])}The broadcast address for each subnet is calculated by adding the subnet size times the subnet number plus subnet size minus one to the network base. The range is the number of subnets.