Files
zogo/nettest/README.md
T
4566704 8a038d4df3 feat(nettest): 自 go-hua 迁入网络连通性探测
- TCP 端口探测 + 原始 ICMP Ping, 持续统计成功率与延迟
- 附测试、examples/nettest 例程与包 README
2026-09-20 12:25:37 +08:00

32 lines
1015 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# nettest
网络连通性测试:TCP 端口探测与原始 ICMP Ping,持续统计成功率与延迟,
适合做线路质量监控探针。
> 迁移自 go-hua/nettest,代码保持原样。
## 用法
```go
import "git.zeroonesoft.cn/golib/zogo/nettest"
// 单次 Ping(addr 支持 IP 或域名)
p := nettest.NewPing("192.168.1.1", 0, 1000) // port=0 表示纯 ICMP
ok := p.Test() // true/false
// 持续探测任务:TCP(echo=false 只测端口) / ICMP,后台 goroutine 运行
nt := nettest.NewNetTest(1, "gateway", "192.168.1.1", 80, 1000, false)
nt.Start()
defer nt.Stop()
time.Sleep(time.Minute)
res := nt.GetResult(true) // TestResult:成功/失败次数、平均延迟等,true 表示取后清零
```
完整可运行例程:[examples/nettest/main.go](../examples/nettest/main.go)
## 注意
- 原始 ICMP 在 Windows 直接可用;Linux 下通常需要 root 或 `cap_net_raw`。
- `NewPing` 的 timeout 单位毫秒;`Ping.Test` 为一次性探测,无统计,统计用 `NetTest`。