Hostanzahl -> CIDR
>>> import math >>> hosts = 256 >>> cidr = 32-int(math.log(int(hosts), 2)) >>> print(cidr) 24
CIDR -> Hostanzahl
>>> import math >>> cidr = 24 >>> hosts = int(math.pow(2,(32-int(cidr)))) >>> print(hosts) 256
CIDR -> Subnetmask
>>> cidr = 24 >>> mask = ".".join([str((((1 << 32) - 1) << (32 - cidr) >> i) & 255) for i in reversed(range(0, 32, 8))]) >>> print(mask) 255.255.255.0
Subnetmask -> CIDR
>>> mask = "255.255.255.0" >>> cidr = sum((bin(x).count('1') for x in [int(x) for x in mask.split(".")])) >>> print(cidr) 24