Skip to content

Cherrling/pingfmt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pingfmt

事实上我完全不会 Go 语言,初衷只是我想要一个结构化的 ping 输出,这个仓库里除了这行字之外所有的内容都是 100% GPT5.4 Vibe Coding 出来的,README 也被 ai 写的很恶心,所以直接拉代码跑就行了

中文

pingfmt 是一个尽可能小的纯 Go Ping 延迟测试工具。

特性

  • 纯 Go 实现,不依赖系统 ping 命令
  • 默认测试 10 次
  • 支持固定间隔发包,行为更接近原版 ping
  • 支持 simplejson 两种输出格式
  • 支持短参数和长参数
  • 支持把地址放在前面或后面
  • 支持 -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:输出格式,支持 simplejson,默认 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 不匹配,程序会给出明确错误提示

English

pingfmt is a minimal pure-Go ping latency tool.

Features

  • Pure Go implementation with no dependency on the system ping command
  • Sends 10 probes by default
  • Uses fixed-interval sending, closer to standard ping behavior
  • Supports both simple and json output
  • Supports short and long flags
  • Supports both target-first and option-first argument order
  • Supports -4 and -6 to force IPv4-only or IPv6-only resolution

Requirements

  • Go 1.25+

Build

go build -o pingfmt .

Run

./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

Flags

  • -c, --count: number of probes, default 10
  • -i, --interval: send interval, default 0.1s
  • -f, --format: output format, simple or json, default simple
  • -4: use IPv4 only
  • -6: use IPv6 only
  • -h, --help: show help

Interval Format

  • Supports 0.1
  • Supports 100ms
  • Supports 0.1s
  • Supports 1s
  • Unitless values default to seconds, so -i 0.2 means -i 0.2s

Output

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.

Notes

  • 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 -4 or -6 is 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages