import socket


def get_ip_for_hostname(hostname, ignore_hostnames_list=["AUTO"]):
    """Get the IP of a given hostname.

    Args:
        hostname (string): hostname to find.
        ignore_hostnames_list (list of strings): special hostname values which
            won't be lookup ip (if the given hostname is in this list, this
            function will return the given hostname without any modification).
    Returns:
        (string) IP of the given hostname (or None if we can't find it).

    """
    if hostname in ignore_hostnames_list:
        return hostname
    if hostname in ("127.0.0.1", "localhost", "localhost.localdomain"):
        return "127.0.0.1"
    try:
        infos = socket.getaddrinfo(hostname, 80, 0, 0, socket.IPPROTO_TCP)
    except Exception:
        return None
    for (family, sockettype, proto, canonname, sockaddr) in infos:
        if sockaddr is None or len(sockaddr) != 2:
            continue
        tmp = sockaddr[0]
        if '.' not in tmp:
            # we don't want ipv6
            continue
        return tmp
    return None