diff --git a/printer/basic.go b/printer/basic.go index e39cc79..a551ad8 100644 --- a/printer/basic.go +++ b/printer/basic.go @@ -2,6 +2,7 @@ package printer import ( "fmt" + "github.com/xgadget-lab/nexttrace/trace" "net" "github.com/fatih/color" @@ -70,3 +71,30 @@ func PrintTraceRouteNav(ip net.IP, domain string, dataOrigin string, maxHops int fmt.Printf("traceroute to %s (%s), %d hops max, 32 byte packets\n", ip.String(), domain, maxHops) } } + +func applyLangSetting(h *trace.Hop) { + if len(h.Geo.Country) <= 1 { + h.Geo.Country = "局域网" + h.Geo.CountryEn = "LAN Address" + } + + if h.Lang == "en" { + if h.Geo.Country == "Anycast" { + + } else if h.Geo.Prov == "骨干网" { + h.Geo.Prov = "BackBone" + } else if h.Geo.ProvEn == "" { + h.Geo.Country = h.Geo.CountryEn + } else { + if h.Geo.CityEn == "" { + h.Geo.Country = h.Geo.ProvEn + h.Geo.Prov = h.Geo.CountryEn + h.Geo.City = "" + } else { + h.Geo.Country = h.Geo.CityEn + h.Geo.Prov = h.Geo.ProvEn + h.Geo.City = h.Geo.CountryEn + } + } + } +} diff --git a/printer/easy.go b/printer/easy.go index a5835a4..2763454 100644 --- a/printer/easy.go +++ b/printer/easy.go @@ -12,6 +12,21 @@ func EasyPrinter(res *trace.Result, ttl int) { fmt.Printf("%d|*||||||\n", ttl+1) continue } - fmt.Printf("%d|%s|%s|%.2f|%s|%s|%s|%s|%s|%s|%.4f|%.4f\n", ttl+1, res.Hops[ttl][i].Address.String(), res.Hops[ttl][i].Hostname, float64(res.Hops[ttl][i].RTT.Microseconds())/1000, res.Hops[ttl][i].Geo.Asnumber, res.Hops[ttl][i].Geo.Country, res.Hops[ttl][i].Geo.Prov, res.Hops[ttl][i].Geo.City, res.Hops[ttl][i].Geo.District, res.Hops[ttl][i].Geo.Owner, res.Hops[ttl][i].Geo.Lat, res.Hops[ttl][i].Geo.Lng) + applyLangSetting(&res.Hops[ttl][i]) + fmt.Printf( + "%d|%s|%s|%.2f|%s|%s|%s|%s|%s|%s|%.4f|%.4f\n", + ttl+1, + res.Hops[ttl][i].Address.String(), + res.Hops[ttl][i].Hostname, + float64(res.Hops[ttl][i].RTT.Microseconds())/1000, + res.Hops[ttl][i].Geo.Asnumber, + res.Hops[ttl][i].Geo.Country, + res.Hops[ttl][i].Geo.Prov, + res.Hops[ttl][i].Geo.City, + res.Hops[ttl][i].Geo.District, + res.Hops[ttl][i].Geo.Owner, + res.Hops[ttl][i].Geo.Lat, + res.Hops[ttl][i].Geo.Lng, + ) } } diff --git a/printer/printer.go b/printer/printer.go index aa3afab..9be92cd 100644 --- a/printer/printer.go +++ b/printer/printer.go @@ -20,6 +20,8 @@ import ( // } // } +//此文件目前仅供classic_printer使用 + const ( RED_PREFIX = "\033[1;31m" GREEN_PREFIX = "\033[1;32m" @@ -33,6 +35,7 @@ func HopPrinter(h trace.Hop, info HopInfo) { if h.Address == nil { fmt.Println("\t*") } else { + applyLangSetting(&h) txt := "\t" if h.Hostname == "" { diff --git a/printer/realtime_printer.go b/printer/realtime_printer.go index 23bbbde..0e48ca5 100644 --- a/printer/realtime_printer.go +++ b/printer/realtime_printer.go @@ -121,30 +121,7 @@ func RealtimePrinter(res *trace.Result, ttl int) { } } - if len(res.Hops[ttl][i].Geo.Country) <= 1 { - res.Hops[ttl][i].Geo.Country = "局域网" - res.Hops[ttl][i].Geo.CountryEn = "LAN Address" - } - - if res.Hops[ttl][i].Lang == "en" { - if res.Hops[ttl][i].Geo.Country == "Anycast" { - - } else if res.Hops[ttl][i].Geo.Prov == "骨干网" { - res.Hops[ttl][i].Geo.Prov = "BackBone" - } else if res.Hops[ttl][i].Geo.ProvEn == "" { - res.Hops[ttl][i].Geo.Country = res.Hops[ttl][i].Geo.CountryEn - } else { - if res.Hops[ttl][i].Geo.CityEn == "" { - res.Hops[ttl][i].Geo.Country = res.Hops[ttl][i].Geo.ProvEn - res.Hops[ttl][i].Geo.Prov = res.Hops[ttl][i].Geo.CountryEn - res.Hops[ttl][i].Geo.City = "" - } else { - res.Hops[ttl][i].Geo.Country = res.Hops[ttl][i].Geo.CityEn - res.Hops[ttl][i].Geo.Prov = res.Hops[ttl][i].Geo.ProvEn - res.Hops[ttl][i].Geo.City = res.Hops[ttl][i].Geo.CountryEn - } - } - } + applyLangSetting(&res.Hops[ttl][i]) if net.ParseIP(ip).To4() != nil {