def ip_network(address, strict=True):
 try:
  return IPv4Network(address, strict)
 except (AddressValueError, NetmaskValueError):
  pass
 try:
  return IPv6Network(address, strict)
 except (AddressValueError, NetmaskValueError):
  pass
 if isinstance(address, bytes):
  raise AddressValueError((u'%r does not appear to be an IPv4 or IPv6 network. Did you pass in a bytes (str in Python 2) instead of a unicode object?' % address))
 raise ValueError((u'%r does not appear to be an IPv4 or IPv6 network' % address))

def ip_network ( address , strict = True ) : try : return IPv4Network ( address , strict ) except ( AddressValueError , NetmaskValueError ) : pass try : return IPv6Network ( address , strict ) except ( AddressValueError , NetmaskValueError ) : pass if isinstance ( address , bytes ) : raise AddressValueError ( ( u'%r does not appear to be an IPv4 or IPv6 network. Did you pass in a bytes (str in Python 2) instead of a unicode object?' % address ) ) raise ValueError ( ( u'%r does not appear to be an IPv4 or IPv6 network' % address ) )
take an ip string/int and return an object of the correct type .