feat: add English support

This commit is contained in:
Leo
2023-02-01 21:34:33 +08:00
parent cc1d6177ca
commit afe18fc4c0
5 changed files with 34 additions and 6 deletions

View File

@@ -54,6 +54,8 @@ func Excute() {
packet_interval := parser.Int("z", "send-time", &argparse.Options{Default: 100, Help: "Set the time interval for sending every packet. Useful when some routers use rate-limit for ICMP messages"})
ttl_interval := parser.Int("i", "ttl-time", &argparse.Options{Default: 500, Help: "Set the time interval for sending packets groups by TTL. Useful when some routers use rate-limit for ICMP messages"})
str := parser.StringPositional(&argparse.Options{Help: "IP Address or domain name"})
lang := parser.Selector("g", "language", []string{"en", "cn"}, &argparse.Options{Default: "cn",
Help: "Choose the language for displaying [en, cn]"})
err := parser.Parse(os.Args)
if err != nil {
@@ -151,6 +153,7 @@ func Excute() {
TTLInterval: *ttl_interval,
NumMeasurements: *numMeasurements,
ParallelRequests: *parallelRequests,
Lang: *lang,
RDns: !*noRdns,
AlwaysWaitRDNS: *alwaysRdns,
IPGeoSource: ipgeo.GetSource(*dataOrigin),

View File

@@ -120,8 +120,30 @@ func RealtimePrinter(res *trace.Result, ttl int) {
fmt.Fprintf(color.Output, " %s", color.New(color.FgHiGreen, color.Bold).Sprintf("%-16s", whoisFormat[0]))
}
}
if len(res.Hops[ttl][i].Geo.Country) <= 1 {
res.Hops[ttl][i].Geo.Country = "LAN Address"
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
}
}
}
if net.ParseIP(ip).To4() != nil {

View File

@@ -30,6 +30,7 @@ type Config struct {
AlwaysWaitRDNS bool
PacketInterval int
TTLInterval int
Lang string
RealtimePrinter func(res *Result, ttl int)
AsyncPrinter func(res *Result)
}
@@ -116,6 +117,7 @@ type Hop struct {
RTT time.Duration
Error error
Geo *ipgeo.IPGeoData
Lang string
}
func (h *Hop) fetchIPData(c Config) (err error) {
@@ -145,6 +147,7 @@ func (h *Hop) fetchIPData(c Config) (err error) {
// Start to fetch IP Geolocation data
if c.IPGeoSource != nil && h.Geo == nil {
res := false
h.Lang = c.Lang
h.Geo, res = ipgeo.Filter(h.Address.String())
if !res {
h.Geo, err = c.IPGeoSource(h.Address.String())

View File

@@ -82,12 +82,12 @@ func (c *WsConn) messageSendHandler() {
// 循环监听发送
select {
case <-c.Done:
log.Println("发送协程已经退出")
log.Println("go-routine has been returned")
return
case t := <-c.MsgSendCh:
// log.Println(t)
if !c.Connected {
c.MsgReceiveCh <- `{"ip":"` + t + `", "asnumber":"API服务端异常"}`
c.MsgReceiveCh <- `{"ip":"` + t + `", "asnumber":"API Server Error"}`
} else {
err := c.Conn.WriteMessage(websocket.TextMessage, []byte(t))
if err != nil {

View File

@@ -19,7 +19,7 @@ func GetFastIP(domain string, port string) string {
ips, err := net.LookupIP(domain)
if err != nil {
log.Fatal("DNS 解析失败,请检查您的系统 DNS 设置")
log.Fatal("DNS resolution failed, please check your system DNS Settings")
return ""
}
@@ -33,12 +33,12 @@ func GetFastIP(domain string, port string) string {
}
if result == "" {
log.Fatal("IP 连接均超时,请检查您的网络")
log.Fatal("IP connection has been timeout, please check your network")
}
res := strings.Split(result, "-")
if len(ips) > 1 {
_, _ = fmt.Fprintf(color.Output, "%s 已为您优选最近的节点 %s - %s\n",
_, _ = fmt.Fprintf(color.Output, "%s prefered API IP - %s - %s\n",
color.New(color.FgWhite, color.Bold).Sprintf("[NextTrace API]"),
color.New(color.FgGreen, color.Bold).Sprintf("%s", res[0]),
color.New(color.FgCyan, color.Bold).Sprintf("%sms", res[1]),