Net Detective
Run structured network diagnostics and explain findings in plain English.
Scripts
- -
scripts/diagnose.py — orchestrates all tests, outputs unified JSON - INLINECODE1 — tests DNS resolution across Google, Cloudflare, and system resolvers
- INLINECODE2 — measures download throughput via curl (no external packages)
- INLINECODE3 — records results over time, detects anomalies vs baseline
- INLINECODE4 — converts diagnostic JSON into a plain-English markdown report
All scripts use Python stdlib only. Cross-platform: macOS and Linux.
Reference references/diagnostic-guide.md for what each test measures and common failure patterns.
Standard Workflow
1. Run the full diagnostic
CODEBLOCK0
Add --speed to include a bandwidth test (adds ~20s):
CODEBLOCK1
Skip traceroute or MTU if time-constrained:
CODEBLOCK2
2. Compare against history (if available)
CODEBLOCK3
If no history exists yet, skip this step.
3. Generate the report
Without history:
CODEBLOCK4
With history comparison:
CODEBLOCK5
4. Record result to history
CODEBLOCK6
Do this after every diagnostic run to build a baseline over time.
Flags Reference
| Script | Flag | Effect |
|---|
| INLINECODE7 | INLINECODE8 | Include bandwidth test |
| INLINECODE9 |
--no-traceroute | Skip traceroute (faster) |
|
diagnose.py |
--no-mtu | Skip MTU detection |
|
speedtest.py |
--quick | Only 100kb + 1mb tests |
|
history.py |
--record <file> | Save result to history |
|
history.py |
--compare <file> | Compare vs baseline |
|
history.py |
--show | Print current baseline |
Interpreting Results
- - DNS failures/slowness — websites appear down even when servers are up; most common cause of "internet is broken" when pings still work
- Packet loss at early hops (1–3) — local network issue (router, cable, Wi-Fi)
- Packet loss at hops 3–6 — ISP problem, outside your control
- High latency, no loss — congestion, either local or upstream
- MTU < 1472 — fragmentation; common with VPNs or PPPoE connections
- Speed drop but latency fine — possible ISP throttling
Read references/diagnostic-guide.md for full pattern descriptions and remediation steps.
Presenting Findings to the User
- - Lead with the headline finding, not raw numbers
- Reference baseline comparisons when available ("This is 3x slower than your normal")
- Give actionable next steps, not just observations
- If the issue is outside the user's control (ISP), say so clearly
网络侦探
运行结构化网络诊断,并用通俗易懂的语言解释结果。
脚本
- - scripts/diagnose.py — 统筹所有测试,输出统一JSON格式
- scripts/dns_check.py — 测试Google、Cloudflare和系统解析器的DNS解析
- scripts/speedtest.py — 通过curl测量下载吞吐量(无需外部包)
- scripts/history.py — 随时间记录结果,检测与基线的异常
- scripts/report.py — 将诊断JSON转换为通俗易懂的Markdown报告
所有脚本仅使用Python标准库。跨平台:macOS和Linux。
参考references/diagnostic-guide.md了解每项测试的测量内容及常见故障模式。
标准工作流程
1. 运行完整诊断
bash
python3 scripts/diagnose.py > /tmp/net-diag.json
添加--speed参数以包含带宽测试(增加约20秒):
bash
python3 scripts/diagnose.py --speed > /tmp/net-diag.json
如果时间有限,可跳过路由追踪或MTU检测:
bash
python3 scripts/diagnose.py --no-traceroute --no-mtu > /tmp/net-diag.json
2. 与历史记录对比(如有)
bash
python3 scripts/history.py --compare /tmp/net-diag.json > /tmp/net-history.json
如果尚无历史记录,请跳过此步骤。
3. 生成报告
无历史记录:
bash
python3 scripts/report.py /tmp/net-diag.json
带历史对比:
bash
python3 scripts/report.py /tmp/net-diag.json --history-compare /tmp/net-history.json
4. 将结果记录到历史
bash
python3 scripts/history.py --record /tmp/net-diag.json
每次诊断运行后执行此操作,以逐步建立基线。
参数参考
| 脚本 | 参数 | 作用 |
|---|
| diagnose.py | --speed | 包含带宽测试 |
| diagnose.py |
--no-traceroute | 跳过路由追踪(更快) |
| diagnose.py | --no-mtu | 跳过MTU检测 |
| speedtest.py | --quick | 仅进行100kb+1mb测试 |
| history.py | --record <文件> | 将结果保存到历史 |
| history.py | --compare <文件> | 与基线对比 |
| history.py | --show | 打印当前基线 |
结果解读
- - DNS故障/缓慢 — 即使服务器正常运行,网站也显示无法访问;当ping仍然正常时,这是网络中断的最常见原因
- 早期跳点(1-3)丢包 — 本地网络问题(路由器、网线、Wi-Fi)
- 跳点3-6丢包 — ISP问题,超出你的控制范围
- 高延迟,无丢包 — 拥塞,可能是本地或上游问题
- MTU < 1472 — 分片问题;常见于VPN或PPPoE连接
- 速度下降但延迟正常 — 可能是ISP限速
阅读references/diagnostic-guide.md获取完整的模式描述和修复步骤。
向用户呈现结果
- - 以关键发现开头,而非原始数据
- 引用基线对比(如适用)(这比你的正常速度慢了3倍)
- 提供可操作的后续步骤,而不仅仅是观察结果
- 如果问题超出用户控制范围(ISP),请明确说明