"""Check alternative SSH ports and Elestio hostname."""
import socket
import subprocess

# Try alternate ports on 91.99.89.7
print("=== Port Scan on 91.99.89.7 ===")
for port in [22, 2222, 2200, 22022, 10022, 80, 443, 8080, 8900]:
    s = socket.socket()
    s.settimeout(3)
    result = s.connect_ex(("91.99.89.7", port))
    s.close()
    if result == 0:
        # Try to get banner
        try:
            s2 = socket.socket()
            s2.settimeout(2)
            s2.connect(("91.99.89.7", port))
            banner = s2.recv(256).decode("utf-8", errors="replace").strip()[:80]
            s2.close()
            print(f"  Port {port}: OPEN  banner={banner!r}")
        except:
            print(f"  Port {port}: OPEN  (no banner)")
    else:
        print(f"  Port {port}: CLOSED")

# Try the Elestio hostname
print("\n=== Port Scan on sunaiva-prod-u50607.vm.elestio.app ===")
try:
    import socket as s_
    ip = s_.gethostbyname("sunaiva-prod-u50607.vm.elestio.app")
    print(f"  Resolved to: {ip}")
    for port in [22, 2222]:
        sock = socket.socket()
        sock.settimeout(3)
        result = sock.connect_ex((ip, port))
        sock.close()
        print(f"  Port {port}: {'OPEN' if result == 0 else 'CLOSED'}")
except Exception as e:
    print(f"  DNS lookup failed: {e}")

# Also check the Sunaiva API endpoint
print("\n=== Sunaiva API Health Check ===")
try:
    import urllib.request
    with urllib.request.urlopen("https://api.sunaivadigital.com/", timeout=8) as r:
        print(f"  Status: {r.status}")
        print(f"  Content: {r.read(200).decode('utf-8', errors='replace')[:200]}")
except Exception as e:
    print(f"  Error: {e}")
