
import socket
import concurrent.futures

# omneconfig.tblから抽出された候補の一部
CANDIDATES = [
    # Paper Trading (ritpz?)
    "ritpz05001.rithmic.com",
    "ritpz25001.rithmic.com",
    "ritpz06001.rithmic.com",
    "ritpz23010.rithmic.com",
    "ritpz01000.01.rithmic.com",
    
    # User (rituz?)
    "rituz00100.00.rithmic.com",
    
    # Common
    "rithmic.com",
    "paper.rithmic.com"
]

PORTS = [65000, 56000, 45454, 64100, 63100]

def check_connection(host, port):
    try:
        # 名前解決
        socket.gethostbyname(host)
        
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.settimeout(1.0)
        result = sock.connect_ex((host, port))
        sock.close()
        if result == 0:
            return f"{host}:{port} -> OPEN"
    except:
        pass
    return None

def scan():
    print("Scanning Rithmic candidates...")
    with concurrent.futures.ThreadPoolExecutor(max_workers=20) as executor:
        futures = []
        for host in CANDIDATES:
            for port in PORTS:
                futures.append(executor.submit(check_connection, host, port))
        
        for future in concurrent.futures.as_completed(futures):
            res = future.result()
            if res:
                print(res)
    print("Scan finished.")

if __name__ == "__main__":
    scan()
