# httpdiff **Repository Path**: tomlen/httpdiff ## Basic Information - **Project Name**: httpdiff - **Description**: HTTP 三路对账镜: 本机解析/公共DNS直连/hosts强制映射, 状态码+采样哈希+重定向链三账对齐。零依赖单文件 CLI - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-10-06 - **Last Updated**: 2026-10-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # httpdiff — HTTP 三路对账镜 > 同一个网址,本机、公共 DNS、hosts 三条路拿到的页面到底一不一样?一次 diff 看清谁在撒谎。 `httpdiff` 是 [dnsdiff](https://github.com/tomlen045/dnsdiff) 的下游姊妹工具: - **dnsdiff** 管「域名指到哪个 IP」(解析层对账) - **httpdiff** 管「连上之后拿到的内容对不对」(内容层对账) 解析一致不代表页面一致——CDN 调度、网关插页、代理劫持、hosts 强制映射,都发生在「连上之后」。httpdiff 把同一个 URL 走三条路各取一遍,逐项对账。 ## 三条路 | 路 | 含义 | 用途 | |---|---|---| | `local` | 本机默认解析直连(getaddrinfo,含 hosts/VPN 映射) | 你实际看到的页面 | | `pinned` | 指定公共 DNS(默认 223.5.5.5)解析出的 IP,直连 + SNI=域名 | 参照系(干净解析) | | `hosts` | `--hosts-file` 中该域名的强制映射直连 | 复现配置态 / 验证映射正确性 | ## 裁决(退出码即结论) | 裁决 | 含义 | |---|---| | `CONSISTENT` | 三路状态码+内容一致 | | `EDGE` / `BODY-SUSPECT` | 同源边缘差异 / 同长不同内容(疑似动态页,去噪不翻红) | | `STATUS-DIVERGE` | 状态码分歧(有路拿不到正常页:403 插页/404 劫持) | | `BODY-DIVERGE` | 内容分歧(状态码同但内容被调包) | | `REDIRECT-DIVERGE` | 重定向链分歧(有路被带去别处) | | `UNREACHABLE` / `PARTIAL` | 全路/部分路无应答 | 退出码:`0`=全部一致或可解释差异;`1`=内部错误;`2`=存在目标级分歧。 ## 安装 零依赖,Python 3.8+ 标准库,单文件: ```bash git clone https://github.com/tomlen045/httpdiff.git cd httpdiff python3 httpdiff.py diff https://example.com ``` ## 用法 ```bash # 三路对账(主命令) python3 httpdiff.py diff https://a.example.com https://b.example.com # 单 URL 快查 python3 httpdiff.py check https://www.example.com # 重定向链逐跳展开 python3 httpdiff.py chain https://github.com # 只看三路各自解析到哪 python3 httpdiff.py routes https://www.example.com # 用 /etc/hosts 做第三路(验证映射与真实页面一致) python3 httpdiff.py diff https://www.example.com --hosts-file /etc/hosts # 动态页关内容哈希 python3 httpdiff.py diff https://www.example.com --nohash ``` 示例输出: ``` == https://example.com local 200 via example.com:443 TLS 73ms len=1256B h=3d7414a921a24780 pinned 200 via 93.184.216.34:443 TLS 78ms len=1256B h=3d7414a921a24780 hosts SKIP no-hosts-mapping 裁决: [=] 三路一致 — 三路状态码+内容一致(1 路跳过) ``` ## 设计不变量 - **INV1 证据性**:每条裁决必带证据(各路状态码/采样哈希/重定向终点/错误原因) - **INV2 幂等**:同一输入连续两次 diff,裁决类别与退出码一致(动态内容用 `--nohash` 退化) - **INV3 只读**:只发 GET,不发写请求,不改本地文件 - **INV4 退出码**:`0` 一致 / `1` 内部错误 / `2` 有分歧 - **INV5 纵深防御**:默认拒绝私网目标(防误伤内网),采样哈希只读前 256KiB - 动态页去噪:同长(或长度差 <5%)且 ≥4KB 的不同哈希判「疑似动态」,不翻红 ## 自测 ```bash python3 selftest.py # 14/14:本地假服务器模拟 一致/内容劫持/403劫持/重定向劫持/部分失联/私网拦截/幂等 ``` ## 不适合什么 - 不是代理抓包工具(看不了完整请求/响应头细节,那是 mitmproxy 的活) - 不做 TLS 信任裁决(证书对不对请用姊妹工具 [certlens](https://github.com/tomlen045/certlens)) - 强动态页面(每次响应都变)请直接 `--nohash`,退化为状态码+重定向链对账 ## 哨兵套件 同系列零依赖诊断工具(每件一个视角): | 工具 | 视角 | |---|---| | [dnsdiff](https://github.com/tomlen045/dnsdiff) | 域名解析三方对账(本机/公共池/多数派) | | [certlens](https://github.com/tomlen045/certlens) | 证书体检(到期/弱密钥/链完整性/端点实测) | | [porteye](https://github.com/tomlen045/porteye) | 端口暴露面 | | **httpdiff** | **HTTP 内容三路对账(本工具)** | ## License MIT