import websocket, json, time, sys IPS = ["192.168.1.188", "192.168.1.18", "192.168.1.1"] for ip in IPS: ws_url = "ws://%s:8080" % ip try: ws = websocket.create_connection(ws_url, timeout=5) print("WS_OK", ip) try: print("HELLO", ws.recv()) except Exception as e: print("HELLO_FAIL", repr(e)) ws.send(json.dumps({"type": "cursor", "visible": True})) time.sleep(0.8) try: print("ACK", ws.recv()) except Exception: print("NO_ACK_NORMAL") ws.close() sys.exit(0) except Exception as e: print("FAIL", ip, repr(e)) print("ALL_FAIL")