#!/usr/bin/env python3
import sys
import paramiko

sys.stdout.reconfigure(encoding="utf-8", errors="replace")


def run(host, user, password, cmd):
    c = paramiko.SSHClient()
    c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    c.connect(host, username=user, password=password, timeout=30, allow_agent=False, look_for_keys=False)
    _, stdout, stderr = c.exec_command(cmd, timeout=60, get_pty=True)
    text = (stdout.read() + stderr.read()).decode("utf-8", "replace")
    print(text)
    c.close()


tests = [
    "curl -sk -m 15 -o /dev/null -w apex=%{http_code} --resolve torbatyar.ir:443:192.168.10.156 https://torbatyar.ir/",
    "curl -sk -m 10 -o /dev/null -w api=%{http_code} --resolve api.torbatyar.ir:443:192.168.10.156 https://api.torbatyar.ir/health",
    "curl -sk -m 10 -o /dev/null -w identity=%{http_code} --resolve identity.torbatyar.ir:443:192.168.10.156 https://identity.torbatyar.ir/health",
    "curl -sk -m 10 -o /dev/null -w auth=%{http_code} --resolve auth.torbatyar.ir:443:192.168.10.156 https://auth.torbatyar.ir/",
    "curl -sS -m 10 -o /dev/null -w demo=%{http_code} -H 'Host: demo.torbatyar.ir' http://192.168.10.156/",
    "curl -sS -m 10 -o /dev/null -w apex80=%{http_code} -H 'Host: torbatyar.ir' http://192.168.10.156/",
]

for t in tests:
    print("CMD:", t)
    run("192.168.10.156", "torbatyaruser", "Moli@5404", t)
    print("---")
