def is_ipaddress(hostname):
if six.PY3 and isinstance(hostname, bytes):<EOL><INDENT>hostname = hostname.decode('<STR_LIT:ascii>')<EOL><DEDENT>families = [socket.AF_INET]<EOL>if hasattr(socket, '<STR_LIT>'):<EOL><INDENT>families.append(socket.AF_INET6)<EOL><DEDENT>for af in families:<EOL><INDENT>try:<EOL><INDENT>inet_pton(af, hostname)<EOL><DEDENT>except (socket.error, ValueError, OSError):<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>return True<EOL><DEDENT><DEDENT>return False<EOL>
Detects whether the hostname given is an IP address.

    :param str hostname: Hostname to examine.
    :return: True if the hostname is an IP address, False otherwise.