def is_valid_ip_address(address):
 if (address.lower() in ('127.0.0.1', 'localhost', '::1', '::ffff:127.0.0.1')):
  return True
 elif (address.lower() in ('unknown', '')):
  return False
 elif (address.count('.') == 3):
  if address.startswith('::ffff:'):
   address = address[7:]
  if hasattr(socket, 'inet_aton'):
   try:
    socket.inet_aton(address)
    return True
   except socket.error:
    return False
  else:
   match = REGEX_IPv4.match(address)
   if (match and all(((0 <= int(match.group(i)) < 256) for i in (1, 2, 3, 4)))):
    return True
   return False
 elif hasattr(socket, 'inet_pton'):
  try:
   socket.inet_pton(socket.AF_INET6, address)
   return True
  except socket.error:
   return False
 else:
  return True

def is_valid_ip_address ( address ) : if ( address . lower ( ) in ( '127.0.0.1' , 'localhost' , '::1' , '::ffff:127.0.0.1' ) ) : return True elif ( address . lower ( ) in ( 'unknown' , '' ) ) : return False elif ( address . count ( '.' ) == 3 ) : if address . startswith ( '::ffff:' ) : address = address [ 7 : ] if hasattr ( socket , 'inet_aton' ) : try : socket . inet_aton ( address ) return True except socket . error : return False else : match = REGEX_IPv4 . match ( address ) if ( match and all ( ( ( 0 <= int ( match . group ( i ) ) < 256 ) for i in ( 1 , 2 , 3 , 4 ) ) ) ) : return True return False elif hasattr ( socket , 'inet_pton' ) : try : socket . inet_pton ( socket . AF_INET6 , address ) return True except socket . error : return False else : return True
check if the provided address is valid ipv4 or ipv6 address .