import socket
import ssl

HOST = "torang-munara.my.id"
PORT = 5364

result = []
try:
    with socket.create_connection((HOST, PORT), timeout=5) as sock:
        sock.settimeout(4)
        try:
            initial = sock.recv(128)
        except socket.timeout:
            initial = b""
        result.append("initial=" + ("telnet_control" if b"\xff" in initial else "other_or_empty"))
except OSError:
    result.append("tcp=failed")

try:
    context = ssl.create_default_context()
    with socket.create_connection((HOST, PORT), timeout=5) as sock:
        with context.wrap_socket(sock, server_hostname=HOST) as tls:
            result.append("tls=negotiated")
except (OSError, ssl.SSLError):
    result.append("tls=not_negotiated")

print("|".join(result))
