def IPNetwork(address, version=None):
 if version:
  if (version == 4):
   return IPv4Network(address)
  elif (version == 6):
   return IPv6Network(address)
 try:
  return IPv4Network(address)
 except (IPv4IpValidationError, IPv4NetmaskValidationError):
  pass
 try:
  return IPv6Network(address)
 except (IPv6IpValidationError, IPv6NetmaskValidationError):
  pass
 raise ValueError(('%r does not appear to be an IPv4 or IPv6 network' % address))

def IPNetwork ( address , version = None ) : if version : if ( version == 4 ) : return IPv4Network ( address ) elif ( version == 6 ) : return IPv6Network ( address ) try : return IPv4Network ( address ) except ( IPv4IpValidationError , IPv4NetmaskValidationError ) : pass try : return IPv6Network ( address ) except ( IPv6IpValidationError , IPv6NetmaskValidationError ) : pass raise ValueError ( ( '%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 .