Skip to content

Commit

Permalink
v0.0.2 - 更新替代fmt的输出
Browse files Browse the repository at this point in the history
  • Loading branch information
spiritLHLS committed Jun 30, 2024
1 parent 8e6a94a commit 6535483
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: |
git config --global user.name 'github-actions'
git config --global user.email '[email protected]'
TAG="v0.0.1-$(date +'%Y%m%d%H%M%S')"
TAG="v0.0.2-$(date +'%Y%m%d%H%M%S')"
git tag $TAG
git push origin $TAG
env:
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ module github.com/oneclickvirt/nt3
go 1.22.4

require (
github.com/fatih/color v1.17.0
github.com/nxtrace/NTrace-core v1.3.1
github.com/oneclickvirt/defaultset v0.0.2-20240624082446
)

require (
github.com/fatih/color v1.17.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
Expand All @@ -33,6 +34,7 @@ require (
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tsosunchia/powclient v0.1.5 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.7.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/nxtrace/NTrace-core v1.3.1 h1:f4z5UaZEuhUP/g6xElpZ2bo+guWITJVrMKrJTqd27oc=
github.com/nxtrace/NTrace-core v1.3.1/go.mod h1:0Px/Zc60qk6cssmP+yv4kstFxvX9sXqDduoVqBO+qf8=
github.com/oneclickvirt/defaultset v0.0.2-20240624082446 h1:5Pg3mK/u/vQvSz7anu0nxzrNdELi/AcDAU1mMsmPzyc=
github.com/oneclickvirt/defaultset v0.0.2-20240624082446/go.mod h1:e9Jt4tf2sbemCtc84/XgKcHy9EZ2jkc5x2sW1NiJS+E=
github.com/oschwald/maxminddb-golang v1.12.0 h1:9FnTOD0YOhP7DGxGsq4glzpGy5+w7pq50AS6wALUMYs=
github.com/oschwald/maxminddb-golang v1.12.0/go.mod h1:q0Nob5lTCqyQ8WT6FYgS1L7PXKVVbgiymefNwIjPzgY=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
Expand Down Expand Up @@ -82,8 +84,12 @@ github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tsosunchia/powclient v0.1.5 h1:hpixFWoPbWSEC0zc9osSltyjtr1+SnhCueZVLkEpyyU=
github.com/tsosunchia/powclient v0.1.5/go.mod h1:yNlzyq+w9llYZV+0q7nrX83ULy4ghq2mCjpTLJFJ2pg=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
Expand Down
2 changes: 1 addition & 1 deletion model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type ParamsFastTrace struct {
}

// var EnableLoger bool
var NextTraceVersion = "v0.0.1"
var NextTraceVersion = "v0.0.2"

var (
GuangZhouCT = fastTrace.ISPCollection{
Expand Down
34 changes: 16 additions & 18 deletions nt/nt.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"strings"
"time"

"github.com/fatih/color"
fastTrace "github.com/nxtrace/NTrace-core/fast_trace"
"github.com/nxtrace/NTrace-core/ipgeo"
"github.com/nxtrace/NTrace-core/trace"
"github.com/nxtrace/NTrace-core/util"
"github.com/nxtrace/NTrace-core/wshandle"
. "github.com/oneclickvirt/defaultset"
"github.com/oneclickvirt/nt3/model"
)

Expand All @@ -42,21 +42,19 @@ func realtimePrinter(res *trace.Result, ttl int) {
tmpMap[v.Address.String()] = append(tmpMap[v.Address.String()], fmt.Sprintf("%-10s", fmt.Sprintf("%.2f ms", v.RTT.Seconds()*1000)))
}
if latestIP == "" {
fmt.Fprintf(color.Output, "%s\n",
color.New(color.FgWhite, color.Bold).Sprintf("*"),
)
fmt.Printf(White("*") + "\n")
return
}
for ip, v := range tmpMap {
i, _ := strconv.Atoi(v[0])
rtt := v[1]
// 打印RTT
fmt.Fprintf(color.Output, fmt.Sprintf("%-24s ", color.New(color.FgHiCyan, color.Bold).Sprintf("%s", rtt)))
fmt.Printf(Cyan("%-24s "), rtt)
// 打印AS号
if res.Hops[ttl][i].Geo.Asnumber != "" {
fmt.Fprintf(color.Output, fmt.Sprintf("%-24s ", color.New(color.FgHiYellow, color.Bold).Sprintf("AS%s", res.Hops[ttl][i].Geo.Asnumber)))
fmt.Printf(Yellow("%-24s "), fmt.Sprintf("AS%s", res.Hops[ttl][i].Geo.Asnumber))
} else {
fmt.Fprintf(color.Output, fmt.Sprintf("%-24s ", color.New(color.FgWhite, color.Bold).Sprintf("*")))
fmt.Printf(White("%-24s "), "*")
}
// 打印地理信息
if net.ParseIP(ip).To4() != nil {
Expand Down Expand Up @@ -94,29 +92,29 @@ func realtimePrinter(res *trace.Result, ttl int) {
case whoisFormat[0] == "[CMIN2-NET]":
fallthrough
case strings.HasPrefix(res.Hops[ttl][i].Address.String(), "59.43."):
fmt.Fprintf(color.Output, "%s", color.New(color.FgHiYellow, color.Bold).Sprintf("%-18s", whoisFormat[0]))
fmt.Printf(Yellow("%s "), fmt.Sprintf("%-18s", whoisFormat[0]))
default:
fmt.Fprintf(color.Output, "%s", color.New(color.FgHiGreen, color.Bold).Sprintf("%-18s", whoisFormat[0]))
fmt.Printf(Green("%s "), fmt.Sprintf("%-18s", whoisFormat[0]))
}
var parts []string
country := res.Hops[ttl][i].Geo.Country
prov := res.Hops[ttl][i].Geo.Prov
city := res.Hops[ttl][i].Geo.City
owner := res.Hops[ttl][i].Geo.Owner
if country != "" {
parts = append(parts, color.New(color.FgWhite, color.Bold).Sprintf("%s", country))
parts = append(parts, White(country))
}
if prov != "" {
parts = append(parts, color.New(color.FgWhite, color.Bold).Sprintf("%s", prov))
parts = append(parts, White(prov))
}
if city != "" {
parts = append(parts, color.New(color.FgWhite, color.Bold).Sprintf("%s", city))
parts = append(parts, White(city))
}
if owner != "" {
parts = append(parts, color.New(color.FgWhite, color.Bold).Sprintf("%s", owner))
parts = append(parts, White(owner))
}
if len(parts) > 0 {
fmt.Fprintf(color.Output, strings.Join(parts, ", "))
fmt.Printf(strings.Join(parts, ", "))
}
}
fmt.Println()
Expand Down Expand Up @@ -231,15 +229,15 @@ func TraceRoute(language, location, testType string) {
if TL != nil {
for _, T := range TL {
if testType == "both" {
fmt.Fprintf(color.Output, "%s - ", color.New(color.FgHiBlue, color.Bold).Sprintf("%s - ICMP v4", T.ISPName))
fmt.Printf(Blue("%s - "), fmt.Sprintf("%s - ICMP v4", T.ISPName))
tracert(ft, T)
fmt.Fprintf(color.Output, "%s - ", color.New(color.FgHiBlue, color.Bold).Sprintf("%s - ICMP v6", T.ISPName))
fmt.Printf(Blue("%s - "), fmt.Sprintf("%s - ICMP v6", T.ISPName))
tracert_v6(ft, T)
} else if testType == "ipv4" {
fmt.Fprintf(color.Output, "%s - ", color.New(color.FgHiBlue, color.Bold).Sprintf("%s - ICMP v4", T.ISPName))
fmt.Printf(Blue("%s - "), fmt.Sprintf("%s - ICMP v4", T.ISPName))
tracert(ft, T)
} else if testType == "ipv6" {
fmt.Fprintf(color.Output, "%s - ", color.New(color.FgHiBlue, color.Bold).Sprintf("%s - ICMP v6", T.ISPName))
fmt.Printf(Blue("%s - "), fmt.Sprintf("%s - ICMP v6", T.ISPName))
tracert_v6(ft, T)
}
time.Sleep(500 * time.Millisecond)
Expand Down

0 comments on commit 6535483

Please sign in to comment.