tplink-archer-be400-cli

loliver1823/tplink-archer-be400-cli Checked 1 day ago

CLI + MCP server for TP-Link Archer BE400 routers - 192 reverse-engineered API endpoints and 14 AI (MCP) tools, including Avira parental-control domain blocking

Full CLI + MCP server for the TP-Link Archer BE400 router — every setting, table and action the web UI has (229 catalogued endpoints, 22 tables, ~40 actions), 34 MCP tools, verified writes and a confirm gate for anything that would drop the household's connection. The goal: never open the router's web UI. This creates a config file at ~/.config/tplink-be400/config.toml. Edit it with your router's IP and password: You can also skip the config file entirely and pass credentials directly:

Summary extracted from the README.

tplink-archer-be400-cli

Full CLI + MCP server for the TP-Link Archer BE400 router — every setting, table and action the web UI has (229 catalogued endpoints, 22 tables, ~40 actions), 34 MCP tools, verified writes and a confirm gate for anything that would drop the household's connection. The goal: never open the router's web UI.

BE400-only. This tool was built by reverse-engineering the Archer BE400's web UI JavaScript bundles (originally firmware v1.0.4, build 2024-09-04; catalog extended and verified against the 2025 firmware / web-UI bundle v1.11.0). It may partially work on other TP-Link routers that share the same firmware platform, but full compatibility is only guaranteed for the BE400.

Installation

pip install git+https://github.com/loliver1823/tplink-archer-be400-cli.git

Or clone and install locally:

git clone https://github.com/loliver1823/tplink-archer-be400-cli.git
cd tplink-archer-be400-cli
pip install .

First-Time Setup

tplink-be400 --setup

This creates a config file at ~/.config/tplink-be400/config.toml. Edit it with your router's IP and password:

[auth]
password = "YourRouterPasswordHere"

[routers.r1]
host = "http://192.168.0.1"
label = "Main Router"

# Multiple routers supported:
# [routers.r2]
# host = "http://192.168.0.202"
# label = "AP Mode Router"

You can also skip the config file entirely and pass credentials directly:

tplink-be400 --host 192.168.0.1 --password YourPassword status

Usage

tplink-be400 <router> <command> [args...]

Where <router> is a key from your config (e.g. r1).

All Commands

Command Description
status Full router overview (CPU, memory, WAN, clients, firmware)
devices List all connected devices (wired + wireless)
wifi WiFi settings for all bands + OFDMA, TWT, WPS, Smart Connect
dhcp DHCP config, lease table, and reservations
wan WAN/internet status, protocols, flow control, double NAT detection
lan LAN IP, subnet, link aggregation, flow control
firewall SPI firewall, IoT security, access control overview
access Access control details (whitelist/blacklist)
parental Parental controls / per-device domain blocking (Avira): parental [list | devices | block | setfilter | delete]
reserve DHCP address reservations (fixed IPs): reserve [list | add <mac> <ip> [name] | remove <mac|ip>]
portfwd Port forwarding: portfwd [list | add <name> <ext_port> <ip> [int_port] [ALL|TCP|UDP] | remove <name|port>]
block / unblock Block a device from the network (access control black list); block alone lists them
wake Wake-on-LAN: wake <mac>
usage Live per-device speeds (usage, usage all) or data used (usage today|week|month [mac])
wifi status / wifi set Wi-Fi summary; wifi set <2g|5g|5g2|6g> ssid=.. password=.. enabled=on hidden=off --yes
nat NAT boost, virtual servers, port triggering, DMZ, ALG
qos QoS bandwidth control, device priority list, game accelerator
ddns Dynamic DNS (TP-Link, DynDNS, No-IP)
upnp UPnP status and active service mappings
imb IP-MAC binding settings and ARP table
ports Physical port status (speed, duplex, WAN/LAN)
iptv IPTV, IGMP snooping, port assignments
guest Guest network and captive portal settings
mesh EasyMesh status and topology
cloud TP-Link cloud account, firmware update check
disk USB disk info and Time Machine settings
speedtest Speed test results and live WAN throughput
rebootsched Scheduled reboot settings
sharing USB/folder/media sharing configuration
logs [TYPE] System logs (filter: NETWORK, NAT, FIREWALL, DHCP, etc.)
mode Operation mode (router/AP/repeater)
firmware Firmware version, auto-upgrade settings, config backup
vpn VPN configs (OpenVPN, PPTP, WireGuard)
admin Administration (remote mgmt, HTTPS, recovery, email alerts)
eco Eco mode / power-saving settings
led LED control and night mode schedule
time Time/NTP and DST settings
diag Router diagnostics
ipv6 Full IPv6 configuration
routes Routing table (system + static routes)

Advanced Commands

Command Description
read <endpoint|path> Read any catalog endpoint or raw admin/x?form=y path (v1/v2 chosen automatically)
write <endpoint> key=value ... Change only the given fields; re-reads and verifies; --yes needed for risky forms
table [<ep> [list|add|update|remove] ...] Any table: table nat/vs add name=web ipaddr=192.168.0.5 external_port=443 internal_port=443 protocol=TCP enable=on; table nat/vs update name=web to external_port=8443; table nat/vs remove name=web
action [<ep> <op> k=v] One-shot operations (WAN renew/release, DDNS refresh, traffic stats, survey, mesh...); --yes for risky ones
reboot Reboot the router (requires confirmation)
endpoints List all known API endpoints
dump Export every readable setting to a JSON file
monitor Continuous network health check (ping + WAN uptime)
discover Scan the LAN for TP-Link admin UIs; optional --subnet, --match-model, --no-auth-discovery, --skip-persist (skip writing config.toml)

Examples

# Full status overview
tplink-be400 r1 status

# List connected devices
tplink-be400 r1 devices

# Check WiFi settings
tplink-be400 r1 wifi

# View firewall rules
tplink-be400 r1 firewall

# Enable WAN ping
tplink-be400 r1 write security/firewall wan_ping=on

# Set up DMZ host
tplink-be400 r1 write nat/dmz enable=on ipaddr=192.168.0.100

# Parental controls: block Smart-TV ad/telemetry domains on one device
tplink-be400 r1 parental block TV-AdBlock D0-D0-03-D5-B4-E4 samsungads.com,samsungacr.com
tplink-be400 r1 parental            # list profiles

# Give a device a fixed IP (use its current address), list, remove
tplink-be400 r1 reserve add aa:bb:cc:11:22:33 192.168.0.13 Solar gateway
tplink-be400 r1 reserve
tplink-be400 r1 reserve remove AA-BB-CC-11-22-33

# Read a raw endpoint
tplink-be400 r1 read wireless/statistics

# Dump everything to JSON
tplink-be400 r1 dump

# Monitor network stability
tplink-be400 r1 monitor

Rate Limiting / Router Stability

The BE400's web server is an embedded system with limited resources. Rapid-fire API calls can crash the router, causing a watchdog reboot with no crash logs.

Guidelines for safe usage:

  • Single commands are always safe. Normal CLI usage (one command at a time) will never cause issues.
  • Scripting: Add at least a 2-second delay between commands. Avoid running dump repeatedly.
  • Session churn: Each CLI invocation creates a new authenticated session (RSA key exchange + AES encryption). Running many commands in rapid succession creates heavy CPU load on the router.
  • The dump command reads all 192 endpoints sequentially and takes ~90 seconds. Don't run it more than once every few minutes.
  • The monitor command uses a 25-second polling interval by design.

If the router becomes unresponsive after heavy API usage, wait 60-90 seconds for it to reboot automatically.

MCP Server (AI Integration)

This package includes an MCP (Model Context Protocol) server that lets AI assistants like Claude and Cursor interact with the router directly through structured tools instead of shell commands.

Why MCP Instead of Shell

  • Persistent session — one RSA+AES handshake reused across all calls (no session churn that can crash the router)
  • Built-in rate limiting — 1.5s minimum between API calls, enforced automatically
  • Structured JSON — every response is clean dicts/lists, not formatted text to parse
  • Auto-reconnect — if the session times out, it silently re-authenticates

MCP Installation

pip install git+https://github.com/loliver1823/tplink-archer-be400-cli.git

Then register the server. For Cursor, create/edit ~/.cursor/mcp.json:

{
  "mcpServers": {
    "tplink-be400": {
      "command": "python",
      "args": ["-m", "tplink_be400.mcp_server"]
    }
  }
}

For Claude Desktop, add to your claude_desktop_config.json:

{
  "mcpServers": {
    "tplink-be400": {
      "command": "python",
      "args": ["-m", "tplink_be400.mcp_server"]
    }
  }
}

Restart your AI client after adding the config. The server reads credentials from the same ~/.config/tplink-be400/config.toml as the CLI.

MCP Tools (34 total)

Tool Description Writes?
router_overview One-call dashboard: firmware, CPU, memory, WAN, WiFi summary, device count, internet status No
list_devices All connected clients with hostname, IP, MAC, connection type No
get_setting Read any topic ("wifi", "wan", "firewall", etc.), endpoint name or raw admin/x?form=y path; optional router key (r1, r2, …) No
change_setting Change only the given fields of a settings form; verified; confirm=true required for Wi-Fi/LAN/WAN/DHCP-server/mesh/VPN/admin forms Yes
get_logs System logs with optional type filter (NETWORK, FIREWALL, NAT, etc.) No
find_endpoints Search the 192-endpoint catalog by keyword No
discover_routers Scan LAN for TP-Link web admin; optional auth; appends new [routers.*] to ~/.config/tplink-be400/config.toml unless skip_persist Yes (local file)
run_diagnostic Ping test + port status + WAN speed in one call No
reboot_router Reboot with mandatory confirm: true safety gate Yes
parental_profiles List Avira parental-control profiles (ownerId, bound MACs, blocked-domain lists) and limits No
parental_devices List devices known to parental controls (name, MAC, type, online) No
parental_block_domains Create a profile that blocks given domains for device MAC(s) — e.g. Samsung TV ad/telemetry. Keeps general internet (HTTPS blocked too, via gateway DNS) Yes
parental_set_filter Replace the blocked-domain list of an existing profile (owner_id, domains) Yes
parental_delete_profile Delete a parental-control profile by owner_id Yes
dhcp_reservations List DHCP address reservations (MAC → fixed IP) and the rule limit No
add_dhcp_reservation Reserve a fixed IP for a MAC (mac, ip, optional name); refuses duplicates, verifies existing rows are untouched Yes
remove_dhcp_reservation Delete one reservation by MAC or IP, verified by re-reading Yes
router_capabilities Every table (with row fields), every action, and features this firmware lacks No
table_rows / table_add / table_update / table_remove Any table (port forwards, port triggering, static routes, IPv6 rules, IP-MAC binding, Wake-on-LAN, block/allow lists, VPN accounts, Wi-Fi schedules...). Verified: exactly one row changes, all others untouched Yes
router_action One-shot operations (renew/release WAN, DDNS refresh, traffic stats, mesh, survey...); confirm gate for risky ones Varies
wifi_status / set_wifi Wi-Fi summary (passwords masked unless asked) / change a band's name, password, on/off, hidden (confirm=true) Yes (set)
port_forwards / add_port_forward / remove_port_forward Port forwarding rules Yes
blocked_devices / block_device / unblock_device Block a device from the network (access control, black list) Yes
wake_device Wake-on-LAN No
live_usage What is using the internet now: live internet down/up and each device's speed (Mbit/s), busiest first (the web UI's Clients data, smart_network?form=game_accelerator op loadDevice) No
usage_history Data used today/this week/this month, whole network or one device, with hourly/daily buckets No

get_setting Topics

The get_setting tool accepts high-level topic names that aggregate multiple endpoints:

wifi, wan, lan, dhcp, firewall, parental, nat, qos, vpn, admin, mesh, ipv6, ddns, upnp, led, eco, time, firmware, disk, sharing, iptv, imb, cloud, logs, ports, routes, guest

Or pass any endpoint shortname (e.g. wireless/ofdma, nat/dmz) for a single raw read. Use find_endpoints to search the catalog.

MCP Examples

# AI calls router_overview → gets full dashboard as JSON
router_overview()
→ { firmware: { model: "Archer BE400", version: "1.1.2 ..." }, performance: { cpu_percent: 11.0, memory_percent: 46.0 }, clients: { total: 20 }, wan: { ip: "180.150.x.x", uptime_human: "4h 23m" }, ... }

# AI calls get_setting with topic "wifi" → gets all WiFi config
get_setting(topic="wifi")
→ { data: { "wireless/wireless_2g": { ssid: "MyNetwork", channel: "6", ... }, ... } }

# AI calls change_setting → changes a setting with confirmation
change_setting(endpoint="security/firewall", settings={"wan_ping": "on"})
→ { success: true, changes: { wan_ping: { before: "off", after: "on" } } }

# AI calls find_endpoints → searches the catalog
find_endpoints(query="vpn")
→ { endpoints: [{ name: "openvpn/config", path: "admin/openvpn?form=config", operation: "read" }, ...] }

Parental Controls (Per-Device Domain Blocking)

The BE400's Avira-based parental controls are exposed via the parental_* tools. Each "profile" (owner) binds one or more device MACs to a blocked-domain list (up to 64 domains). Blocking is enforced at the gateway via DNS manipulation, so it also drops HTTPS connections to those domains while leaving the device's general internet intact. A common use is killing Smart-TV ad/telemetry without touching the rest of the network.

# Block Samsung Smart TV ad/telemetry on one device
parental_block_domains(
  name="TV-AdBlock",
  macs="D0-D0-03-D5-B4-E4",
  domains="samsungads.com,samsungadhub.com,samsungacr.com",
)
→ { success: true, data: { ownerId: 0 } }

# Inspect, edit, or remove later
parental_profiles()                                          # find the ownerId + current lists
parental_set_filter(owner_id="0", domains="samsungads.com,extra.com")   # replaces the list
parental_delete_profile(owner_id="0")                        # removes the block

Wire format note: parental controls use the admin/avira_parental_control endpoint and its own request shape in avira.py (operation and params in the URL query, a bare-blob response). It works because without a form Content-Type the router dispatches on the URL; see "How requests are sent" below.

DHCP Address Reservations (Fixed IPs)

reserve (CLI) and the *_dhcp_reservation tools give a device the same address every time — useful for anything another system talks to by IP (inverter gateways, Home Assistant, NAS). Use the device's current IP so nothing has to reconnect.

dhcp_reservations()                                                   # list
add_dhcp_reservation(mac="aa:bb:cc:11:22:33", ip="192.168.0.13", name="Solar gateway")
remove_dhcp_reservation(mac_or_ip="192.168.0.13")
  • An add refuses a MAC or IP that is already reserved; remove it first to change it. Both operations re-read the list and report success: false if the result is not exactly one row added/removed with every other row unchanged.
  • If the router already knows the device, it stores the device's own hostname instead of the supplied name.
  • change_setting refuses table endpoints; use the table_* tools.

How requests are sent (2.0.0)

api.py sends every request exactly as the web UI does (firmware 1.11 JS, update-store-*.js):

  • v1 forms: encrypted body operation=<op>&k=v... (URL-encoded values, JSON for objects) with Content-Type: application/x-www-form-urlencoded, and nothing in the URL query.
  • v2 JSON (paths the UI prefixes with /v2, listed in api.V2_PATHS): encrypted JSON plaintext, envelope posted as a JSON body.

Bug fixed in 2.0.0: tplinkrouterc6u's request() posts without a Content-Type, so the router ignored the body and acted on the URL alone. Reads worked because 1.x appended &operation=read to the URL, but writes, row inserts and removes ran with no parameters: write/change_setting reported success and changed nothing (the LED form, which toggles on every write, flipped instead), inserts created blank rows, and removes did nothing. With the Content-Type set, an operation in the URL as well gets "no such callback".

Other behaviour learned in the 2026-11-03 audit (audit/AUDIT-2026-11-03.md):

  • Write only the fields you change. Echoing a whole form back is unsafe, and write_form never re-sends a value that is already set (the LED switch toggles on any write).
  • Tables the UI loads over v2 must use v2 for every operation; the UI's own v1 remove there fails.
  • Empty tables load as {}, so table-ness comes from capabilities.TABLES, not the data shape.
  • The router may rewrite fields on save (e.g. a DHCP reservation takes the device's own hostname); verified results list them under router_rewrote.

One login at a time

The router keeps a single admin session: each new login (CLI, MCP, the web UI, or a poller such as Home Assistant's router-stats feed) replaces the previous one. The replaced client then gets an empty reply; api.SessionExpired is raised and the MCP tools log in again and retry automatically. Table adds refuse to duplicate an identical row, so a retried add is safe. A long-running poller should back off when its session is replaced (router-stats pauses 3 minutes) so interactive changes are not interrupted.

Router speeds (downloadSpeed, uploadSpeed, WAN down_speed/up_speed) are bytes per second; the web UI multiplies by 8 to show bits.

Risk levels

capabilities.risk() classifies every change. Disruptive (Wi-Fi, LAN/WAN, DHCP server, mesh, IPTV, VPN, admin access, access-control mode) and destructive (reboot, firmware/config restore, disk format, cloud binding, operation mode, router login) changes need confirm=true (MCP) or --yes (CLI). Without it nothing is sent and the reason is returned.

How It Works

This tool communicates with the router's internal web API — the same API that the browser-based admin panel uses. All endpoints were discovered by reverse-engineering the router's JavaScript bundles.

Authentication uses RSA + AES encryption (handled by the tplinkrouterc6u library). Every request goes through the same encrypted channel as the web UI.

Dependencies

Compatibility

Router Firmware Status
Archer BE400 v1.0 1.0.4 (2024) – v1.11.0 (2025) Fully tested
Other TP-Link routers — May partially work

License

MIT