def get_mask_ipv4(bits):
 if ((bits > 32) or (bits < 0)):
  raise ValueError(('A mask can only be 0-32 bits, got %i' % bits))
 elif (bits == 32):
  return FULL_IPv4_MASK
 mask_bin = _get_binary(((2 ** bits) - 1), 32)[::(-1)]
 octets = [mask_bin[(8 * i):(8 * (i + 1))] for i in range(4)]
 return '.'.join([str(int(octet, 2)) for octet in octets])

def get_mask_ipv4 ( bits ) : if ( ( bits > 32 ) or ( bits < 0 ) ) : raise ValueError ( ( 'A mask can only be 0-32 bits, got %i' % bits ) ) elif ( bits == 32 ) : return FULL_IPv4_MASK mask_bin = _get_binary ( ( ( 2 ** bits ) - 1 ) , 32 ) [ : : ( - 1 ) ] octets = [ mask_bin [ ( 8 * i ) : ( 8 * ( i + 1 ) ) ] for i in range ( 4 ) ] return '.' . join ( [ str ( int ( octet , 2 ) ) for octet in octets ] )
provides the ipv4 mask for a given number of bits .