Documentation
¶
Index ¶
- Constants
- func ClassicPrinter(res *trace.Result, ttl int)
- func CopyRight()
- func EasyPrinter(res *trace.Result, ttl int)
- func FormatIPGeoData(ip string, data *ipgeo.IPGeoData) string
- func FormatMTRRawLine(rec trace.MTRRawRecord) string
- func GetRouter(r *map[string][]string, node string)
- func HopPrinter(h trace.Hop, info HopInfo)
- func MTRReportPrint(stats []trace.MTRHopStat, opts MTRReportOptions)
- func MTRTUIPrinter(target, domain, targetIP, version string, startTime time.Time, ...) func(iteration int, stats []trace.MTRHopStat)
- func MTRTUIRender(w io.Writer, header MTRTUIHeader, stats []trace.MTRHopStat)
- func MTRTUIRenderString(header MTRTUIHeader, stats []trace.MTRHopStat) string
- func MTRTablePrinter(stats []trace.MTRHopStat, iteration int, mode int, nameMode int, lang string, ...)
- func New() table.Table
- func PrintTraceRouteNav(ip net.IP, domain string, dataOrigin string, maxHops int, packetSize int, ...)
- func RealtimePrinter(res *trace.Result, ttl int)
- func RealtimePrinterWithRouter(res *trace.Result, ttl int)
- func TracerouteTablePrinter(res *trace.Result, clearScreen bool)
- func Version()
- type HopInfo
- type MTRReportOptions
- type MTRRow
- type MTRTUIHeader
- type MTRTUIStatus
Constants ¶
const ( HostModeBase = 0 // 仅 IP/PTR HostModeASN = 1 // ASN + IP/PTR HostModeCity = 2 // ASN + IP/PTR + 城市 HostModeOwner = 3 // ASN + IP/PTR + owner HostModeFull = 4 // ASN + IP/PTR + full )
const ( HostNamePTRorIP = 0 // 默认:有 PTR 显示 PTR,否则 IP HostNameIPOnly = 1 // 始终显示 IP )
const ( RED_PREFIX = "\033[1;31m" GREEN_PREFIX = "\033[1;32m" YELLOW_PREFIX = "\033[1;33m" BLUE_PREFIX = "\033[1;34m" CYAN_PREFIX = "\033[1;36m" RESET_PREFIX = "\033[0m" )
Variables ¶
This section is empty.
Functions ¶
func ClassicPrinter ¶
func EasyPrinter ¶
func FormatIPGeoData ¶ added in v1.6.1
func FormatMTRRawLine ¶ added in v1.5.2
func FormatMTRRawLine(rec trace.MTRRawRecord) string
FormatMTRRawLine formats one MTR raw stream record with fixed 12 columns: ttl|ip|ptr|rtt|asn|country|prov|city|district|owner|lat|lng
func HopPrinter ¶
func MTRReportPrint ¶ added in v1.5.2
func MTRReportPrint(stats []trace.MTRHopStat, opts MTRReportOptions)
MTRReportPrint 以 mtr -rzw 风格将最终统计一次性输出到 stdout。
输出格式(示例):
Start: 2025-07-14T09:12:00+0800 HOST: myhost Loss% Snt Last Avg Best Wrst StDev 1. AS4134 one.one.one.one 0.0% 10 1.23 1.45 0.98 2.10 0.32 2. ??? 100.0% 10 0.00 0.00 0.00 0.00 0.00
Wide 模式下使用 HostModeFull(完整地址 + 运营商),host 列宽度取所有行最大值; 非 wide 模式仅显示 PTR/IP,不查询/展示 GEO,也不显示 MPLS,按终端宽度截断:
width < 100 → maxHost = 16 100 ≤ width < 140 → maxHost = 20 width ≥ 140 → maxHost = 24
func MTRTUIPrinter ¶ added in v1.5.2
func MTRTUIPrinter(target, domain, targetIP, version string, startTime time.Time, srcHost, srcIP, lang string, apiInfo func() string, showIPs bool, isPaused func() bool, displayMode func() int, nameMode func() int, isMPLSDisabled func() bool) func(iteration int, stats []trace.MTRHopStat)
MTRTUIPrinter 返回一个可直接用作 MTROnSnapshot 的回调函数, 将帧渲染到 os.Stdout。
func MTRTUIRender ¶ added in v1.5.2
func MTRTUIRender(w io.Writer, header MTRTUIHeader, stats []trace.MTRHopStat)
MTRTUIRender 将 MTR TUI 帧渲染到 w。 每帧重新获取终端宽度并计算自适应布局。
func MTRTUIRenderString ¶ added in v1.5.2
func MTRTUIRenderString(header MTRTUIHeader, stats []trace.MTRHopStat) string
MTRTUIRenderString 将 MTR TUI 帧渲染为字符串(方便测试)。
func MTRTablePrinter ¶ added in v1.5.2
func MTRTablePrinter(stats []trace.MTRHopStat, iteration int, mode int, nameMode int, lang string, showIPs bool)
MTRTablePrinter 将 MTR 快照渲染为经典 MTR 风格表格。 每次调用都会先清屏再重绘。
func PrintTraceRouteNav ¶
func RealtimePrinter ¶
func TracerouteTablePrinter ¶
Types ¶
type MTRReportOptions ¶ added in v1.5.2
type MTRReportOptions struct {
StartTime time.Time
SrcHost string
Wide bool
ShowIPs bool
Lang string
}
MTRReportOptions 控制报告输出细节。
type MTRRow ¶ added in v1.5.2
type MTRRow struct {
Hop string
Loss string
Snt string
Last string
Avg string
Best string
Wrst string
StDev string
Host string
}
MTRRow 表示表格中一行经过格式化的数据。
func MTRRenderTable ¶ added in v1.5.2
func MTRRenderTable(stats []trace.MTRHopStat, mode int, nameMode int, lang string, showIPs bool) []MTRRow
MTRRenderTable 仅返回格式化后的行数据(用于测试/非终端场景)。 mode / nameMode / lang 控制 Host 列内容;传 -1 / -1 / "" 等效于 HostModeFull + HostNamePTRorIP + "en"(向后兼容)。
type MTRTUIHeader ¶ added in v1.5.2
type MTRTUIHeader struct {
Target string
StartTime time.Time
Status MTRTUIStatus
Iteration int
// 以下为 v2 新增字段
Domain string // 用户输入的域名(可为空)
TargetIP string // 解析后的目标 IP
Version string // 软件版本,如 "v1.3.0"
// 以下为 v3 新增字段
SrcHost string // 源主机名
SrcIP string // 源 IP
Lang string // 语言("en" / "cn")
DisplayMode int // 显示模式 0-4
NameMode int // Host 基础显示 0=PTR/IP, 1=IP only
ShowIPs bool // 是否显示 PTR+IP(nameMode=0 时生效)
APIInfo string // preferred API 信息(纯文本,可为空)
DisableMPLS bool // 是否隐藏 MPLS 行(运行时 toggle)
}
MTRTUIHeader 包含帧顶部显示的元信息。
type MTRTUIStatus ¶ added in v1.5.2
type MTRTUIStatus int
MTRTUIStatus 表示 TUI 当前运行状态。
const ( MTRTUIRunning MTRTUIStatus = iota MTRTUIPaused )