事实上我完全不会 Go 语言,初衷只是我想要一个结构化的 ping 输出,这个仓库里除了这行字之外所有的内容都是 100% GPT5.4 Vibe Coding 出来的,README 也被 ai 写的很恶心,所以直接拉代码跑就行了
pingfmt 是一个尽可能小的纯 Go Ping 延迟测试工具。
- 纯 Go 实现,不依赖系统
ping命令 - 默认测试 10 次
- 支持固定间隔发包,行为更接近原版 ping
- 支持
simple和json两种输出格式 - 支持短参数和长参数
- 支持把地址放在前面或后面
- 支持
-4和-6指定仅使用 IPv4 或 IPv6
- Go 1.25+
go build -o pingfmt ../pingfmt 8.8.8.8
./pingfmt -4 example.com
./pingfmt -6 example.com
./pingfmt -c 20 -i 100ms baidu.com
./pingfmt baidu.com -c 20 -i 100ms
./pingfmt --count 5 --interval 0.2s --format json 1.1.1.1
./pingfmt -f json github.com-c,--count:测试次数,默认10-i,--interval:发包间隔,默认0.1s-f,--format:输出格式,支持simple或json,默认simple-4:仅使用 IPv4-6:仅使用 IPv6-h,--help:显示帮助
- 支持
0.1 - 支持
100ms - 支持
0.1s - 支持
1s - 不带单位时默认按秒处理,例如
-i 0.2等价于-i 0.2s
simple 输出会显示:
- target
- address
- packets sent / received / loss
- latency min / avg / max / jitter
json 输出会返回结构化结果,包含原始统计字段和每次采样延迟。
- 这是纯 Go ICMP 实现,但是否能够正常收发 ICMP 仍然受操作系统权限、网络策略和防火墙影响
- 程序优先选择可用的 IPv4 地址,如果没有则回退到 IPv6
- 对域名使用
-4或-6时,会只选择对应版本的解析结果 - 如果目标地址与
-4/-6不匹配,程序会给出明确错误提示
pingfmt is a minimal pure-Go ping latency tool.
- Pure Go implementation with no dependency on the system
pingcommand - Sends 10 probes by default
- Uses fixed-interval sending, closer to standard ping behavior
- Supports both
simpleandjsonoutput - Supports short and long flags
- Supports both target-first and option-first argument order
- Supports
-4and-6to force IPv4-only or IPv6-only resolution
- Go 1.25+
go build -o pingfmt ../pingfmt 8.8.8.8
./pingfmt -4 example.com
./pingfmt -6 example.com
./pingfmt -c 20 -i 100ms baidu.com
./pingfmt baidu.com -c 20 -i 100ms
./pingfmt --count 5 --interval 0.2s --format json 1.1.1.1
./pingfmt -f json github.com-c,--count: number of probes, default10-i,--interval: send interval, default0.1s-f,--format: output format,simpleorjson, defaultsimple-4: use IPv4 only-6: use IPv6 only-h,--help: show help
- Supports
0.1 - Supports
100ms - Supports
0.1s - Supports
1s - Unitless values default to seconds, so
-i 0.2means-i 0.2s
simple output shows:
- target
- address
- packets sent / received / loss
- latency min / avg / max / jitter
json output returns structured data including the summary fields and per-probe latency samples.
- This is a pure-Go ICMP implementation, but ICMP traffic may still be affected by OS permissions, firewall rules, or network policy
- The program prefers IPv4 when available and falls back to IPv6 otherwise
- When
-4or-6is used with a hostname, only that address family is selected - If the target does not match the requested family, the program returns a clear error