#!/usr/bin/env python3 """ utun control socket monitor client Usage: python3 monitor.py [host] [port] Default: localhost:5555 """ import socket import struct import sys import json import time # Command types from control_socket.h CONTROL_CMD_GET_STATS = 1 CONTROL_CMD_RESET_STATS = 2 CONTROL_CMD_GET_STATUS = 3 # Response types CONTROL_RESP_STATS = 1 CONTROL_RESP_STATUS = 2 CONTROL_RESP_ERROR = 3 # Error codes CONTROL_ERR_NONE = 0 CONTROL_ERR_INVALID_CMD = 1 CONTROL_ERR_INTERNAL = 2 def send_command(host='192.168.29.117', port=5555, command=CONTROL_CMD_GET_STATS, sequence=1): """Send a control command and receive response""" sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.settimeout(2.0) # Build request packet (4 bytes: command + sequence) # struct control_request_packet_t { uint16_t command; uint16_t sequence; } request = struct.pack(' 1: host = sys.argv[1] if len(sys.argv) > 2: port = int(sys.argv[2]) print(f"Connecting to {host}:{port}") # Send GET_STATS command data = send_command(host, port, CONTROL_CMD_GET_STATS, 1) if data is None: return print(f"Received {len(data)} bytes") print_hex(data) # Attempt to parse basic info if len(data) >= 6: resp_type, err_code, seq = struct.unpack('= 14: timestamp = struct.unpack('= 6: resp_type, err_code, seq = struct.unpack('