
import socket
import sys

# Windowsホストのローカルポートをチェック
PORTS = [56000, 52000, 65000, 3010, 3011, 3012, 3013]
HOST = "127.0.0.1"

print(f"Checking TCP ports on {HOST}...")
open_ports = []
for port in PORTS:
    try:
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
            s.settimeout(0.5)
            res = s.connect_ex((HOST, port))
            if res == 0:
                print(f"  [OPEN]   {port}")
                open_ports.append(port)
            else:
                print(f"  [CLOSED] {port}")
    except Exception as e:
        print(f"  [ERROR]  {port}: {e}")

if not open_ports:
    print("No target ports are open.")
    sys.exit(1)
else:
    print(f"Found open ports: {open_ports}")
    sys.exit(0)
