def natural_ipv4_netmask(ip, fmt='prefixlen'):
 bits = _ipv4_to_bits(ip)
 if bits.startswith('11'):
  mask = '24'
 elif bits.startswith('1'):
  mask = '16'
 else:
  mask = '8'
 if (fmt == 'netmask'):
  return cidr_to_ipv4_netmask(mask)
 else:
  return ('/' + mask)

def natural_ipv4_netmask ( ip , fmt = 'prefixlen' ) : bits = _ipv4_to_bits ( ip ) if bits . startswith ( '11' ) : mask = '24' elif bits . startswith ( '1' ) : mask = '16' else : mask = '8' if ( fmt == 'netmask' ) : return cidr_to_ipv4_netmask ( mask ) else : return ( '/' + mask )
returns the "natural" mask of an ipv4 address .