update: fix channel closed, printer imrove

This commit is contained in:
sjlleo
2022-05-22 19:55:27 +08:00
parent ead46decf6
commit 8c8d58d02b
8 changed files with 31 additions and 23 deletions

View File

@@ -8,6 +8,6 @@ type tokenData struct {
var token = tokenData{
ipinsight: "",
ipinfo: "42764a944dabd0",
ipinfo: "",
ipleo: "NextTraceDemo",
}

View File

@@ -5,10 +5,6 @@ import (
"net"
)
func PrintCopyRight() {
fmt.Println("NextTrace v0.1.0 Alpha \nxgadget-lab zhshch (xzhsh.ch) & leo (leo.moe)")
}
func PrintTraceRouteNav(ip net.IP, domain string, dataOrigin string) {
fmt.Println("IP Geo Data Provider: " + dataOrigin)

View File

@@ -2,9 +2,10 @@ package printer
import (
"fmt"
"github.com/xgadget-lab/nexttrace/trace"
"strings"
"github.com/xgadget-lab/nexttrace/trace"
"github.com/xgadget-lab/nexttrace/ipgeo"
)

View File

@@ -2,9 +2,10 @@ package printer
import (
"fmt"
"github.com/xgadget-lab/nexttrace/trace"
"strings"
"github.com/xgadget-lab/nexttrace/trace"
"github.com/fatih/color"
"github.com/rodaine/table"
)
@@ -30,7 +31,16 @@ func TracerouteTablePrinter(res *trace.Result) {
if k > 0 {
data.Hop = ""
}
tbl.AddRow(data.Hop, data.IP, data.Latency, data.Asnumber, data.Country, data.Prov, data.City, data.Owner)
if data.Country == "" && data.Prov == "" && data.City == "" {
tbl.AddRow(data.Hop, data.IP, data.Latency, data.Asnumber, "", data.Owner)
} else {
if data.City != "" {
tbl.AddRow(data.Hop, data.IP, data.Latency, data.Asnumber, data.Country+", "+data.Prov+", "+data.City, data.Owner)
} else {
tbl.AddRow(data.Hop, data.IP, data.Latency, data.Asnumber, data.Country, data.Owner)
}
}
}
}
// 打印表格
@@ -42,7 +52,7 @@ func New() table.Table {
headerFmt := color.New(color.FgGreen, color.Underline).SprintfFunc()
columnFmt := color.New(color.FgYellow).SprintfFunc()
tbl := table.New("Hop", "IP", "Lantency", "ASN", "Country", "Province", "City", "Owner")
tbl := table.New("Hop", "IP", "Lantency", "ASN", "Location", "Owner")
tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt)
return tbl
}

View File

@@ -155,12 +155,12 @@ func (t *ICMPTracer) send(fork workFork) error {
t.inflightRequest[fork.num] = hopCh
t.inflightRequestLock.Unlock()
defer func() {
t.inflightRequestLock.Lock()
close(hopCh)
delete(t.inflightRequest, fork.ttl)
t.inflightRequestLock.Unlock()
}()
// defer func() {
// t.inflightRequestLock.Lock()
// close(hopCh)
// delete(t.inflightRequest, fork.ttl)
// t.inflightRequestLock.Unlock()
// }()
if fork.num == 0 && t.Config.RoutePath {
fmt.Print(strconv.Itoa(fork.ttl))

View File

@@ -155,12 +155,12 @@ func (t *ICMPTracerv6) send(fork workFork) error {
t.inflightRequest[fork.num] = hopCh
t.inflightRequestLock.Unlock()
defer func() {
t.inflightRequestLock.Lock()
close(hopCh)
delete(t.inflightRequest, fork.ttl)
t.inflightRequestLock.Unlock()
}()
// defer func() {
// t.inflightRequestLock.Lock()
// close(hopCh)
// delete(t.inflightRequest, fork.ttl)
// t.inflightRequestLock.Unlock()
// }()
if fork.num == 0 && t.Config.RoutePath {
fmt.Print(strconv.Itoa(fork.ttl))

View File

@@ -41,7 +41,7 @@ func (t *TCPTracerv6) Execute() (*Result, error) {
}
t.SrcIP, _ = util.LocalIPPort(t.DestIP)
log.Println(util.LocalIPPort(t.DestIP))
var err error
t.tcp, err = net.ListenPacket("ip6:tcp", t.SrcIP.String())
if err != nil {
@@ -207,7 +207,7 @@ func (t *TCPTracerv6) send(ttl int) error {
return err
}
ipv6.NewPacketConn(t.tcp)
ipv6.NewPacketConn(t.tcp).SetHopLimit(ttl)
if err != nil {
return err
}

View File

@@ -71,6 +71,7 @@ func Traceroute(method Method, config Config) (*Result, error) {
if config.DestIP.To4() != nil {
tracer = &TCPTracer{Config: config}
} else {
// tracer = &TCPTracerv6{Config: config}
return nil, errors.New("IPv6 TCP Traceroute is not supported")
}
default: