diff --git a/ipgeo/tokens.go b/ipgeo/tokens.go index fdeb68d5..c49077dc 100644 --- a/ipgeo/tokens.go +++ b/ipgeo/tokens.go @@ -8,6 +8,6 @@ type tokenData struct { var token = tokenData{ ipinsight: "", - ipinfo: "42764a944dabd0", + ipinfo: "", ipleo: "NextTraceDemo", } diff --git a/printer/basic.go b/printer/basic.go index cd55f00c..0c3d02e6 100644 --- a/printer/basic.go +++ b/printer/basic.go @@ -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) diff --git a/printer/printer.go b/printer/printer.go index de0b1a38..e43cb26c 100644 --- a/printer/printer.go +++ b/printer/printer.go @@ -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" ) diff --git a/printer/tableprinter.go b/printer/tableprinter.go index c91b2826..08e663d0 100644 --- a/printer/tableprinter.go +++ b/printer/tableprinter.go @@ -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 } diff --git a/trace/icmp_ipv4.go b/trace/icmp_ipv4.go index efa24e9b..f5de7835 100644 --- a/trace/icmp_ipv4.go +++ b/trace/icmp_ipv4.go @@ -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)) diff --git a/trace/icmp_ipv6.go b/trace/icmp_ipv6.go index 93d78ec1..5c80388e 100644 --- a/trace/icmp_ipv6.go +++ b/trace/icmp_ipv6.go @@ -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)) diff --git a/trace/tcp_ipv6.go b/trace/tcp_ipv6.go index 3be1fd5f..252cbee8 100644 --- a/trace/tcp_ipv6.go +++ b/trace/tcp_ipv6.go @@ -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 } diff --git a/trace/trace.go b/trace/trace.go index 4649b5df..4fef395b 100644 --- a/trace/trace.go +++ b/trace/trace.go @@ -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: