import socket, time

HOST="112.199.81.2"; PORT=35601

def connect_try(label, payload=None, wait=6):
    try:
        s = socket.create_connection((HOST, PORT), timeout=6)
        s.settimeout(wait)
        got = b""
        # send immediately
        if payload is not None:
            s.sendall(payload)
        # read for wait seconds
        try:
            while True:
                c = s.recv(4096)
                if not c: break
                got += c
        except socket.timeout:
            pass
        s.close()
        print(f"[{label}] CONNECTED, got {len(got)} bytes: {got[:120]!r}")
        return True
    except Exception as e:
        print(f"[{label}] {type(e).__name__}: {e}")
        return False

# Long wait for any banner
connect_try("long-wait 15s no data", None, wait=15)

# TLS ClientHello raw
tls_hello = bytes.fromhex("1603010200010001fc0303" + "11"*32 + "20" + "00"*32 + "002a" + "130113021303c02bc02fc02cc030cca9cca8c013c014009c009d002f0035000a0100" + "018900000000" )
# simpler: use a full hello from openssl
import subprocess
hello = subprocess.run(["bash","-c","timeout 2 openssl s_client -connect %s:%d -tls1_2 -msg 2>/dev/null | head -c 2000"%(HOST,PORT)], capture_output=True, timeout=8)
print("[openssl -msg]", hello.stdout[:600])

time.sleep(3)
connect_try("0x00 x200", b"\x00"*200, wait=6)
time.sleep(3)
connect_try("newline x100", b"\r\n"*50, wait=6)
