def calc_net(ipaddr, netmask=None):
 if (netmask is not None):
  ipaddr = '{0}/{1}'.format(ipaddr, netmask)
 return str(ipaddress.ip_network(ipaddr, strict=False))

def calc_net ( ipaddr , netmask = None ) : if ( netmask is not None ) : ipaddr = '{0}/{1}' . format ( ipaddr , netmask ) return str ( ipaddress . ip_network ( ipaddr , strict = False ) )
returns the cidr of a subnet based on an ip address and optional netmask .