def do_check(nowip, condition):
    result = False
    import OpenSSL
    import socket
    import re
    context = OpenSSL.SSL.Context(OpenSSL.SSL.TLSv1_METHOD)
    socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    socket.settimeout(1)
    connection = OpenSSL.SSL.Connection(context, socket)
    if condition["sni"]:
        connection.set_tlsext_host_name(condition["host"])
    try:
        connection.connect(
            (nowip, condition["port"]))
    except KeyboardInterrupt:
        exit()
    except:
        print(nowip + " Error")
        return
    connection.setblocking(True)
    try:
        connection.do_handshake()
    except __HOLE__:
        exit()
    except OpenSSL.SSL.WantReadError:
        print(nowip + " Timeout")
        return
    except:
        print(nowip + " Error")
        return
    cert = connection.get_peer_certificate()
    data = []
    for no in range(0, cert.get_extension_count()):
        if cert.get_extension(no).get_short_name() != b"subjectAltName":
            continue
        data = re.sub(
            r"\\[\s\S]", "#",
            re.sub(
                r"\\x[0-9a-zA-Z]{2}", "#",
                (str(cert.get_extension(no).get_data())
                    .replace(r"b\"", "").replace("\"", "")
                    .replace(r"b'", "")
                    .replace(r"'", "").replace("\\\\", "\\")))).split("#")
        for item in data:
            if item != "" and item != "0":
                if item.find(condition["common_name_has"]) != -1:
                    print(nowip + " True, DNS Name=" + item)
                    result = True
                else:
                    print(nowip + " False, DNS Name=" + item)
    if len(data) == 0:
        certname = OpenSSL.crypto.X509Name(cert.get_subject())
        if certname.commonName.find(condition["common_name_has"]) != -1:
            print(nowip + " True, CN=" + certname.commonName)
            result = True
        else:
            print(nowip + " False, CN=" + certname.commonName)
    return result
dataset/ETHPy150Open futursolo/host-witness/witness.py/do_check