openwrt_list_dhcp_leases
List all DHCP leases to view connected devices with their IP and MAC addresses on an OpenWRT router.
Instructions
List all DHCP leases (connected devices with IP/MAC addresses)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- openwrt_ssh_mcp/tools.py:158-198 (handler)The main handler function that executes the DHCP leases listing. It tries two possible lease file locations (/tmp/dhcp.leases and /var/dhcp.leases), parses the output, and returns a structured list of leases with timestamp, MAC, IP, hostname, and client_id for each device.@staticmethod async def list_dhcp_leases() -> dict[str, Any]: """ List DHCP leases (connected devices). Returns: dict: DHCP leases information """ # Try both possible locations for DHCP leases file commands = [ "cat /tmp/dhcp.leases", "cat /var/dhcp.leases", ] for cmd in commands: result = await OpenWRTTools.execute_command(cmd) if result["success"] and result["output"]: # Parse DHCP leases leases = [] for line in result["output"].strip().split("\n"): if line: parts = line.split() if len(parts) >= 4: leases.append({ "timestamp": parts[0], "mac": parts[1], "ip": parts[2], "hostname": parts[3] if len(parts) > 3 else "", "client_id": parts[4] if len(parts) > 4 else "", }) return { "success": True, "leases": leases, "count": len(leases), } return { "success": False, "error": "Could not read DHCP leases file", }
- openwrt_ssh_mcp/server.py:97-105 (schema)Tool schema definition in the list_tools() function. Defines the tool name, description, and input schema (empty object with no required parameters).Tool( name="openwrt_list_dhcp_leases", description="List all DHCP leases (connected devices with IP/MAC addresses)", inputSchema={ "type": "object", "properties": {}, "required": [], }, ),
- openwrt_ssh_mcp/server.py:316-317 (registration)Tool routing in the call_tool() function that maps the tool name 'openwrt_list_dhcp_leases' to its handler implementation OpenWRTTools.list_dhcp_leases().elif name == "openwrt_list_dhcp_leases": result = await OpenWRTTools.list_dhcp_leases()