psandis/wiremonitor

GitHub: psandis/wiremonitor

一个基于浏览器的本地网络流量实时仪表盘,读取 SQLite 数据库并以可视化方式展示连接、AI 分析与会话统计。

Stars: 0 | Forks: 0

# wiremonitor [![npm](https://img.shields.io/npm/v/wiremonitor?style=flat-square)](https://www.npmjs.com/package/wiremonitor) 网络流量 Web 仪表盘。读取由 [wirewatch](https://github.com/psandis/wirewatch) 生成的本地 SQLite 数据库,并在浏览器中显示实时连接、AI 分析和会话统计信息。无云端,无遥测。 wiremonitor 提供本地 HTTP 仪表盘服务,并通过 Server-Sent Events 将新连接实时流式传输到浏览器。它以只读模式读取数据库——永远不会写入,也不会干扰捕获守护进程。 ## 它能做什么 - 在 `http://localhost:PORT` 提供本地 Web 仪表盘服务 - 随着新记录的到来,通过 Server-Sent Events 流式传输实时连接 - 显示连接表,支持按协议、方向、进程、国家和目标 IP 筛选 - 点击显示包含完整元数据的连接详情 - 列出包含风险等级、摘要的 AI 分析,以及按进程和目标分组的标记连接 - 按名称识别已知进程(VS Code、Chrome、Slack、node 等) - 显示包含可视化细分(包括热门进程和热门国家)的数据库和会话统计信息 - 显示实时更新的守护进程状态(运行中 / 已停止) - 实时 SSE 状态指示器显示浏览器流是否已连接 - 深色和浅色主题切换,跨会话持久化 - 启动时自动打开浏览器 ## 环境要求 - Node.js 22+ - 由 wirewatch 或兼容捕获守护进程生成的本地 SQLite 数据库 用于开发或从源码构建: - pnpm 10.33.0+ ## 安装 ``` npm install -g wiremonitor ``` 验证安装: ``` wm --help ``` `wm` 命令现已全局可用。 ### 从源码构建 ``` git clone https://github.com/psandis/wiremonitor.git cd wiremonitor pnpm install pnpm build npm link ``` 验证: ``` wm --help ``` `wm` 命令现已全局可用。 ## 快速开始 启动仪表盘: ``` wm --db ~/.wirewatch/wirewatch.db ``` ``` wiremonitor running at http://localhost:3311 ``` 将在默认浏览器中自动打开。当有新连接到达时会自动更新。使用 `Ctrl+C` 停止。 ## 仪表盘 ### 头部 固定头部显示: - **WM logo** — 左侧的品牌标志 - **状态指示器** — 捕获守护进程运行时为绿色并带有脉冲效果,停止时为红色,每 5 秒轮询一次 - **实时指示器** — 显示 SSE 流的状态:`connecting`、`connected`(绿色脉冲)或 `offline`(红色)。每次接收到新事件时会短暂闪烁 - **主题切换** — 在深色和浅色模式之间切换,持久化到 localStorage - **导航** — 连接 / 分析 / 统计 ### 连接 一个按最新记录排在最前的捕获连接实时表。 | 列 | 描述 | |--------|-------------| | ID | 连接 ID | | Proto | TCP 或 UDP | | Source | 源 IP 和端口 | | Destination | 目标主机名或 IP 和端口 | | Dir | 方向:outbound / inbound / local | | State | 连接状态(ESTABLISHED、TIME_WAIT 等) | | Process | 发起该连接的进程名 | | CC | 目标国家代码 | | Last Seen | 最后活动时间戳 | 表格上方的筛选栏: | 筛选项 | 描述 | |--------|-------------| | Protocol | TCP 或 UDP | | Direction | outbound / inbound / local | | Process | 进程名精确匹配 | | Country | 两位字母国家代码 | | IP chip | 点击分析中的目标时激活 — 显示目标 IP,点击 ✕ 清除 | 方向以箭头徽章显示:`→` outbound,`←` inbound,`⇄` local。 新行在 SSE 流传输时从顶部以动画形式插入。点击某行会从右侧滑入一个详情面板,显示完整的连接记录。 ### 分析 一个可滚动的分析卡片列表。每张卡片显示一个风险徽章(低 / 中 / 高,带颜色标识)、时间戳、AI 提供商和模型、连接计数以及通俗易懂的摘要。摘要文本中提及的目标 IP 是可点击的——点击其中一个将按该 IP 筛选连接视图。 被标记的连接先按进程分组,再按目标分组。每个进程条目显示原始进程名,并在已知的情况下在括号内显示解析后的完整名称(例如 `Code H (VS Code Helper)`)。每个目标行显示主机名或 IP、带有协议标签的端口(例如 `443 HTTPS`)以及连接计数徽章。点击具有单个连接的目标会打开详情面板;点击具有多个连接的目标将按该目标 IP 筛选连接视图。 进程名通过 `public/process-labels.json` 解析——这是一个普通的 JSON 文件,你可以直接扩展而无需重新构建。 ### 统计 统计磁贴显示关键数字:总连接数、分析数、会话数、最早记录和数据库大小。CSS 条形图显示: - 协议分布(TCP / UDP) - 方向分布(outbound / inbound / local) - 按连接数排名的前 10 个进程 - 按连接数排名的前 10 个国家 - 按连接数排名的前 10 个目标 ## 配置 | 键 | 默认值 | 描述 | |-----|---------|-------------| | `server.port` | `3311` | HTTP 服务器端口 | | `server.host` | `127.0.0.1` | 绑定地址。设置为 `0.0.0.0` 可监听所有网络接口 | | `server.openBrowser` | `true` | 启动时自动打开浏览器 | | `server.ssePollInterval` | `2000` | SSE 轮询间隔(以毫秒为单位) | | `db.path` | | SQLite 数据库文件的绝对路径 | 编辑 `~/.wiremonitor/config.json` 以设置值: ``` { "server": { "port": 3311, "host": "127.0.0.1", "openBrowser": true, "ssePollInterval": 2000 }, "db": { "path": "/path/to/your/database.db" } } ``` 或在启动时传递标志: | 标志 | 描述 | |------|-------------| | `--port ` | HTTP 服务器端口 | | `--host ` | 绑定地址 | | `--no-open` | 启动时不打开浏览器 | | `--db ` | SQLite 数据库文件的路径 | | `--config` | 打印当前配置并退出 | ## 存储 默认根目录: ``` ~/.wiremonitor/ ``` | 路径 | 描述 | |------|-------------| | `~/.wiremonitor/config.json` | wiremonitor 配置 | 覆盖根目录: ``` export WIREMONITOR_HOME=/path/to/custom/root ``` ## API wiremonitor 在与仪表盘相同的端口上暴露了一个本地 REST API。 | 方法 | 路径 | 描述 | |--------|------|-------------| | GET | `/api/connections` | 列出连接 | | GET | `/api/connections/:id` | 单个连接详情 | | GET | `/api/analyses` | 列出分析 | | GET | `/api/stats` | 数据库统计 | | GET | `/api/status` | 守护进程状态 | | GET | `/api/events` | SSE 流 — 当新记录到达时发出 `connection` 事件 | 所有端点均返回 JSON。 ### 查询参数 `GET /api/connections` 接受: | 参数 | 描述 | |-----------|-------------| | `limit` | 结果数量(默认:100,最大:1000) | | `offset` | 分页偏移量 | | `since` | 以毫秒为单位的 Unix 时间戳 — 返回此时间之后的连接 | | `protocol` | 按协议筛选:`TCP` 或 `UDP` | | `direction` | 按方向筛选:`inbound`、`outbound` 或 `local` | | `process` | 按进程名筛选(精确匹配) | | `dst_ip` | 按目标 IP 筛选 | ## Agent 集成 ### OpenClaw 技能 全局安装(`npm install -g wiremonitor`)后,向你的工作区添加一个 `SKILL.md`: ``` --- name: wiremonitor description: View live network connections, AI analyses, and traffic statistics in a browser dashboard version: 1.0.0 requires_binaries: - wm --- When the user asks about network traffic or wants to view connections visually, use the wiremonitor API: - To fetch recent connections: GET http://localhost:3311/api/connections - To get connection detail: GET http://localhost:3311/api/connections/:id - To list AI analyses: GET http://localhost:3311/api/analyses - To get database stats: GET http://localhost:3311/api/stats - To check daemon status: GET http://localhost:3311/api/status ``` ## 技术栈 | 工具 | 用途 | |------|---------| | TypeScript | 编程语言 | | Node.js 22+ | 运行时 | | better-sqlite3 | 只读 SQLite 访问 | | node:http | HTTP 服务器,无框架 | | Vanilla JS / HTML / CSS | 仪表盘,无前端框架,无构建步骤 | | Server-Sent Events | 实时连接流传输 | | Vitest | 测试 | | Biome | 代码检查与格式化 | | tsup | 构建 | ## 文件结构 ``` wiremonitor/ ├── src/ │ ├── server.ts entry point — starts HTTP server, opens browser │ ├── types.ts shared TypeScript types │ └── lib/ │ ├── config.ts configuration load, save, and validation │ ├── db.ts read-only SQLite queries │ ├── router.ts HTTP request routing │ ├── sse.ts Server-Sent Events connection manager │ └── api/ │ ├── connections.ts GET /api/connections, GET /api/connections/:id │ ├── analyses.ts GET /api/analyses │ ├── stats.ts GET /api/stats │ └── status.ts GET /api/status ├── public/ │ ├── index.html dashboard shell │ ├── app.js dashboard logic (vanilla JS) │ ├── style.css styles │ └── process-labels.json process name resolution map (extend without rebuilding) ├── tests/ │ ├── config.test.ts │ ├── db.test.ts │ ├── router.test.ts │ └── sse.test.ts ├── package.json ├── tsconfig.json ├── tsup.config.ts ├── vitest.config.ts ├── biome.json ├── LICENSE └── README.md ``` ## 开发 ``` git clone https://github.com/psandis/wiremonitor.git cd wiremonitor pnpm install pnpm build npm link ``` 运行 `npm link` 后,执行 `wm` 以启动仪表盘。 ``` pnpm test pnpm typecheck pnpm lint ``` ## 测试 ``` pnpm test ``` 当前情况: - 跨 config、db、router 和 sse 模块共有 64 个测试 - 集成测试使用端口 0 上的真实 HTTP 服务器和真实的已初始化 SQLite 数据库 - SSE 测试使用伪造的计时器来验证轮询器行为,无需真实延迟 ## 相关项目 - 🦀 [Wirewatch](https://github.com/psandis/wirewatch) — 带有 AI 异常检测的网络流量捕获守护进程 - 🦀 [Psclawmcp](https://github.com/psandis/psclawmcp) — OpenClaw CLI 生态系统的 MCP 服务器 - 🦀 [Feedclaw](https://github.com/psandis/feedclaw) — RSS/Atom 提要阅读器和 AI 摘要生成器 - 🦀 [Dustclaw](https://github.com/psandis/dustclaw) — 找出是什么在占用你的磁盘空间 - 🦀 [Driftclaw](https://github.com/psandis/driftclaw) — 跨环境的部署漂移检测 - 🦀 [Dietclaw](https://github.com/psandis/dietclaw) — 代码库健康监控器 - 🦀 [Mymailclaw](https://github.com/psandis/mymailclaw) — 电子邮件扫描器、分类器和清理器 - 🦀 [OpenClaw](https://github.com/openclaw/openclaw) — 开源 AI 助手 ## 许可证 参见 [MIT](LICENSE)
标签:AI分析, GNU通用公共许可证, MITM代理, Node.js, pnpm, Server-Sent Events, SQLite, SSE, Web仪表盘, 仪表板, 会话统计, 实时连接, 局域网监控, 开源安全工具, 无遥测, 暗黑模式, 本地优先, 流量告警, 网络安全, 网络数据可视化, 网络测绘, 自动化攻击, 进程识别, 逆向工程平台, 防御绕过, 隐私保护, 风险等级