def cidr_to_ipv4_netmask(cidr_bits):
 try:
  cidr_bits = int(cidr_bits)
  if (not (1 <= cidr_bits <= 32)):
   return ''
 except ValueError:
  return ''
 netmask = ''
 for idx in range(4):
  if idx:
   netmask += '.'
  if (cidr_bits >= 8):
   netmask += '255'
   cidr_bits -= 8
  else:
   netmask += '{0:d}'.format((256 - (2 ** (8 - cidr_bits))))
   cidr_bits = 0
 return netmask

def cidr_to_ipv4_netmask ( cidr_bits ) : try : cidr_bits = int ( cidr_bits ) if ( not ( 1 <= cidr_bits <= 32 ) ) : return '' except ValueError : return '' netmask = '' for idx in range ( 4 ) : if idx : netmask += '.' if ( cidr_bits >= 8 ) : netmask += '255' cidr_bits -= 8 else : netmask += '{0:d}' . format ( ( 256 - ( 2 ** ( 8 - cidr_bits ) ) ) ) cidr_bits = 0 return netmask
returns an ipv4 netmask .