import socket for p in [10250, 10255, 9100]: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(2) res = s.connect_ex(('140.44.4.41', p)) s.close() print(f"Spaceport 140.44.4.41:{p} -> {'OPEN' if res == 0 else 'CLOSED'}")