mirror of
https://github.com/nxtrace/NTrace-core.git
synced 2025-08-12 06:26:39 +00:00
fix bug:raw和classic模式增加语言个性化输出
注意:classic模式将会被废弃,请不要在此模式基础上开发
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 == "" {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user