network
Retrieve and diagnose network data on Windows systems, including adapters, connections, ports, routing, DNS details, and perform tests like ping, traceroute, and port scanning.
Instructions
Network information and diagnostics including network adapters, connections, ports, routing, and network testing
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | The network operation to perform | |
| count | No | Number of ping packets to send (default: 4) | |
| host | No | Target host for ping, traceroute, or port scanning | |
| port | No | Specific port number for port-related operations | |
| port_range | No | Port range for scanning (e.g., '80-443') | |
| protocol | No | Protocol filter for connections and ports (default: all) | all |
| timeout | No | Timeout in seconds for network operations (default: 5) |
Implementation Reference
- src/tools/network.ts:49-92 (handler)Main handler function that executes the network tool logic by dispatching to specific sub-functions based on the 'action' parameter.async run(args: { action: string; host?: string; port?: number; port_range?: string; protocol?: string; count?: number; timeout?: number; }) { try { switch (args.action) { case "get_network_adapters": return await this.getNetworkAdapters(); case "get_active_connections": return await this.getActiveConnections(args.protocol); case "get_listening_ports": return await this.getListeningPorts(args.protocol); case "get_routing_table": return await this.getRoutingTable(); case "ping_host": return await this.pingHost(args.host!, args.count); case "trace_route": return await this.traceRoute(args.host!); case "get_dns_info": return await this.getDnsInfo(); case "get_network_statistics": return await this.getNetworkStatistics(); case "scan_open_ports": return await this.scanOpenPorts(args.host!, args.port_range); case "get_wifi_profiles": return await this.getWifiProfiles(); default: throw new Error(`Unknown action: ${args.action}`); } } catch (error: any) { return { content: [{ type: "text", text: `❌ Network operation failed: ${error.message}` }], isError: true }; } },
- src/tools/network.ts:9-46 (schema)Input schema defining parameters for the network tool, including actions like get_network_adapters, ping_host, etc.parameters: { type: "object", properties: { action: { type: "string", enum: ["get_network_adapters", "get_active_connections", "get_listening_ports", "get_routing_table", "ping_host", "trace_route", "get_dns_info", "get_network_statistics", "scan_open_ports", "get_wifi_profiles"], description: "The network operation to perform" }, host: { type: "string", description: "Target host for ping, traceroute, or port scanning" }, port: { type: "number", description: "Specific port number for port-related operations" }, port_range: { type: "string", description: "Port range for scanning (e.g., '80-443')" }, protocol: { type: "string", enum: ["tcp", "udp", "all"], description: "Protocol filter for connections and ports (default: all)", default: "all" }, count: { type: "number", description: "Number of ping packets to send (default: 4)", default: 4 }, timeout: { type: "number", description: "Timeout in seconds for network operations (default: 5)", default: 5 } }, required: ["action"]
- src/index.ts:52-56 (registration)Registration of the network tool in the ListToolsRequestHandler, providing name, description, and inputSchema.{ name: networkTool.name, description: networkTool.description, inputSchema: networkTool.parameters },
- src/index.ts:81-82 (registration)Handler registration in the CallToolRequestSchema switch statement that invokes networkTool.run.case "network": return await networkTool.run(args as any);
- src/tools/network.ts:94-111 (helper)Helper function to retrieve network adapter information and IP configuration using PowerShell commands.async getNetworkAdapters() { try { const command = `Get-NetAdapter | Select-Object Name, InterfaceDescription, Status, LinkSpeed, MediaType, PhysicalMediaType | Format-Table -AutoSize`; const { stdout } = await execAsync(`powershell -Command "${command}"`); // Also get IP configuration const ipCommand = `Get-NetIPAddress | Where-Object {$_.AddressFamily -eq 'IPv4'} | Select-Object InterfaceAlias, IPAddress, PrefixLength | Format-Table -AutoSize`; const { stdout: ipInfo } = await execAsync(`powershell -Command "${ipCommand}"`); const result = `# Network Adapters\n\n## Adapter Information\n\`\`\`\n${stdout}\n\`\`\`\n\n## IP Configuration\n\`\`\`\n${ipInfo}\n\`\`\``; return { content: [{ type: "text", text: result }] }; } catch (error: any) { throw new Error(`Failed to get network adapters: ${error.message}`); } },