Skip to content

Commit

Permalink
feat: add English support
Browse files Browse the repository at this point in the history
  • Loading branch information
sjlleo committed Feb 1, 2023
1 parent cc1d617 commit afe18fc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
3 changes: 3 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -151,6 +153,7 @@ func Excute() {
TTLInterval: *ttl_interval,
NumMeasurements: *numMeasurements,
ParallelRequests: *parallelRequests,
Lang: *lang,
RDns: !*noRdns,
AlwaysWaitRDNS: *alwaysRdns,
IPGeoSource: ipgeo.GetSource(*dataOrigin),
Expand Down
24 changes: 23 additions & 1 deletion printer/realtime_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions wshandle/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions wshandle/latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}

Expand All @@ -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]),
Expand Down

0 comments on commit afe18fc

Please sign in to comment.