def get_ip_spec(addr, subnet=None):
  """Get the IP address with the subnet prefix length.

  Args:
    addr: network.addr object
    subnet: network.net object

  Returns:
    A string of the IP address with prefix length.

  Raises:
    Exception: if ip not in subnet
  """
  if subnet is None:
    if addr.version == 6:
      ip_spec = str(addr) + '/128'
    else:
      ip_spec = str(addr) + '/32'
  elif addr in subnet:
    ip_spec = '%s/%s' % (addr, subnet.prefixlen)
  else:
    raise Exception('ip %s is not in subnet %s' % (addr, subnet))
  return ip_spec