Skip to main content
Glama

inspect_network

Check network interfaces and connection status on servers using hostname, username, and optional parameters like port and timeout for remote diagnostics.

Instructions

检查网络接口和连接状态

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostnameYes
passwordNo
portNo
timeoutNo
usernameYes

Implementation Reference

  • Core implementation of the inspect_network tool: connects via SSH, retrieves network interfaces with 'ip a', parses them, gets listening ports with 'ss -tuln', checks internet with ping to 8.8.8.8.
    @handle_exceptions def inspect_network( hostname: str, username: str, password: str = "", port: int = 22, timeout: int = 30 ) -> dict: """检查网络接口和连接状态""" result = {"status": "unknown", "interfaces": [], "connections": {}, "error": ""} try: with SSHManager(hostname, username, password, port, timeout) as ssh: # 获取网络接口信息 interfaces_command = "ip a" stdin, stdout, stderr = ssh.exec_command(interfaces_command, timeout=timeout) interfaces_output = stdout.read().decode().strip() # 解析网络接口信息 result["interfaces"] = ServerInspector.parse_network_interfaces(interfaces_output) # 获取网络连接信息 connections_command = "ss -tuln" stdin, stdout, stderr = ssh.exec_command(connections_command, timeout=timeout) connections_output = stdout.read().decode().strip() # 解析监听端口 listening_ports = [] for line in connections_output.split('\n')[1:]: # 跳过标题行 if "LISTEN" in line: parts = line.split() if len(parts) >= 5: address_port = parts[4] if ":" in address_port: port = address_port.split(":")[-1] listening_ports.append(port) result["connections"]["listening_ports"] = listening_ports # 检查是否可以连接公网 internet_check = ssh.exec_command("ping -c 1 -W 2 8.8.8.8", timeout=timeout) internet_output = internet_check[1].read().decode().strip() result["connections"]["internet_connectivity"] = "1 received" in internet_output result["status"] = "success" except Exception as e: result["status"] = "error" result["error"] = str(e) return result
  • SSE variant of the inspect_network tool handler, functionally identical to the main version.
    @handle_exceptions def inspect_network( hostname: str, username: str, password: str = "", port: int = 22, timeout: int = 30 ) -> dict: """检查网络接口和连接状态""" result = {"status": "unknown", "interfaces": [], "connections": {}, "error": ""} try: with SSHManager(hostname, username, password, port, timeout) as ssh: # 获取网络接口信息 interfaces_command = "ip a" stdin, stdout, stderr = ssh.exec_command(interfaces_command, timeout=timeout) interfaces_output = stdout.read().decode().strip() # 解析网络接口信息 result["interfaces"] = ServerInspector.parse_network_interfaces(interfaces_output) # 获取网络连接信息 connections_command = "ss -tuln" stdin, stdout, stderr = ssh.exec_command(connections_command, timeout=timeout) connections_output = stdout.read().decode().strip() # 解析监听端口 listening_ports = [] for line in connections_output.split('\n')[1:]: # 跳过标题行 if "LISTEN" in line: parts = line.split() if len(parts) >= 5: address_port = parts[4] if ":" in address_port: port = address_port.split(":")[-1] listening_ports.append(port) result["connections"]["listening_ports"] = listening_ports # 检查是否可以连接公网 internet_check = ssh.exec_command("ping -c 1 -W 2 8.8.8.8", timeout=timeout) internet_output = internet_check[1].read().decode().strip() result["connections"]["internet_connectivity"] = "1 received" in internet_output result["status"] = "success" except Exception as e: result["status"] = "error" result["error"] = str(e) return result
  • Registration of inspect_network in the tools dictionary and dynamic @mcp.tool() decoration in the FastMCP server.
    tools_dict = { 'get_memory_info': get_memory_info, 'remote_server_inspection': remote_server_inspection, 'get_system_load': get_system_load, 'monitor_processes': monitor_processes, 'check_service_status': check_service_status, 'get_os_details': get_os_details, 'check_ssh_risk_logins': check_ssh_risk_logins, 'check_firewall_config': check_firewall_config, 'security_vulnerability_scan': security_vulnerability_scan, 'backup_critical_files': backup_critical_files, 'inspect_network': inspect_network, 'analyze_logs': analyze_logs, 'list_docker_containers': list_docker_containers, 'list_docker_images': list_docker_images, 'list_docker_volumes': list_docker_volumes, 'get_container_logs': get_container_logs, 'monitor_container_stats': monitor_container_stats, 'check_docker_health': check_docker_health } # 使用装饰器动态注册所有工具 for name, func in tools_dict.items(): mcp.tool()(func)
  • Manual dispatch and call to inspect_network in the SSE server's tool_handler function.
    elif name == "inspect_network": required_args = ["hostname", "username"] for arg in required_args: if arg not in arguments: raise ValueError(f"Missing required argument '{arg}'") result = inspect_network( hostname=arguments["hostname"], username=arguments["username"], password=arguments.get("password", ""), port=arguments.get("port", 22), timeout=arguments.get("timeout", 30) )
  • Tool schema definition including name, description, and parameters for inspect_network.
    {"name": "inspect_network", "description": "检查网络接口和连接状态", "parameters": [ {"name": "hostname", "type": "str", "default": None}, {"name": "username", "type": "str", "default": None}, {"name": "password", "type": "str", "default": ""}, {"name": "port", "type": "int", "default": 22}, {"name": "timeout", "type": "int", "default": 30} ]},

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Heht571/ops-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server