Complete the code to represent the CIDR notation for the IP address 192.168.1.0 with a subnet mask of 24 bits.
cidr = "192.168.1.0/[1]"
The CIDR notation uses a slash followed by the number of bits in the subnet mask. For a common subnet mask of 255.255.255.0, the number of bits is 24.
Complete the code to calculate the number of possible hosts in a subnet given the CIDR prefix length.
hosts = 2**(32 - [1]) - 2
The number of hosts is calculated by subtracting the prefix length from 32 (total bits in IPv4), then raising 2 to that power and subtracting 2 for network and broadcast addresses.
Fix the error in the code that converts a CIDR prefix length to a subnet mask in dotted decimal format.
subnet_mask = '.'.join(str((0xffffffff << (32 - [1]) >> i) & 0xff) for i in [24,16,8,0])
The variable representing the CIDR prefix length should be named consistently. Here, 'prefix_length' is the correct variable to use.
Fill both blanks to create a dictionary comprehension that maps CIDR prefixes to their subnet masks in dotted decimal format for prefixes 24 and 16.
cidr_to_mask = {prefix: '.'.join(str((0xffffffff << (32 - prefix) >> i) & 0xff) for i in [1]) for prefix in [2]The bit shifts for each octet are 24, 16, 8, and 0. The prefixes to map are 24 and 16.
Fill all three blanks to create a dictionary comprehension that maps CIDR prefixes to the number of hosts available in each subnet for prefixes 28, 26, and 24.
hosts_per_subnet = {prefix: 2**(32 - [1]) - [2] for prefix in [3]The variable 'prefix' is used for each CIDR prefix. The number 2 is subtracted to exclude network and broadcast addresses. The prefixes are 28, 26, and 24.