def in_subnet(cidr, addr=None):
 try:
  cidr = ipaddress.ip_network(cidr)
 except ValueError:
  log.error("Invalid CIDR '{0}'".format(cidr))
  return False
 if (addr is None):
  addr = ip_addrs()
  addr.extend(ip_addrs6())
 elif isinstance(addr, six.string_types):
  return (ipaddress.ip_address(addr) in cidr)
 for ip_addr in addr:
  if (ipaddress.ip_address(ip_addr) in cidr):
   return True
 return False

def in_subnet ( cidr , addr = None ) : try : cidr = ipaddress . ip_network ( cidr ) except ValueError : log . error ( "Invalid CIDR '{0}'" . format ( cidr ) ) return False if ( addr is None ) : addr = ip_addrs ( ) addr . extend ( ip_addrs6 ( ) ) elif isinstance ( addr , six . string_types ) : return ( ipaddress . ip_address ( addr ) in cidr ) for ip_addr in addr : if ( ipaddress . ip_address ( ip_addr ) in cidr ) : return True return False
returns true if host is within specified subnet .