fix bugs:ft下maxhops、pktsize不正常显示、tracemap在配置环境变量时不能正常使用、trace时无法显示第一跳

This commit is contained in:
tsosunchia
2023-06-04 04:12:57 +08:00
parent 85df0121fd
commit dcce91614f
5 changed files with 70 additions and 63 deletions

View File

@@ -9,7 +9,6 @@ import (
"os/signal"
"runtime"
"strings"
"sync"
"time"
"github.com/akamensky/argparse"
@@ -99,6 +98,7 @@ func Excute() {
AlwaysWaitRDNS: *alwaysRdns,
Lang: *lang,
PktSize: *packetSize,
Timeout: time.Duration(*timeout) * time.Millisecond,
}
fastTrace.FastTest(*tcp, *output, paramsFastTrace)
@@ -144,46 +144,50 @@ func Excute() {
*disableMaptrace = true
}
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
if strings.ToUpper(*dataOrigin) == "LEOMOEAPI" {
val, ok := os.LookupEnv("NEXTTRACE_DATAPROVIDER")
if ok {
*dataOrigin = val
} else {
w := wshandle.New()
w.Interrupt = make(chan os.Signal, 1)
signal.Notify(w.Interrupt, os.Interrupt)
defer func() {
w.Conn.Close()
}()
}
/**
* 此处若使用goroutine同时运行ws的建立与nslookup
* 会导致第一跳的IP信息无法获取原因不明。
*/
//var wg sync.WaitGroup
//wg.Add(2)
//
//go func() {
// defer wg.Done()
if strings.ToUpper(*dataOrigin) == "LEOMOEAPI" {
val, ok := os.LookupEnv("NEXTTRACE_DATAPROVIDER")
if ok {
*dataOrigin = val
} else {
w := wshandle.New()
w.Interrupt = make(chan os.Signal, 1)
signal.Notify(w.Interrupt, os.Interrupt)
defer func() {
w.Conn.Close()
}()
}
}()
go func() {
defer wg.Done()
if *udp {
if *ipv6Only {
fmt.Println("[Info] IPv6 UDP Traceroute is not supported right now.")
os.Exit(0)
}
}
//}()
//
//go func() {
// defer wg.Done()
if *udp {
if *ipv6Only {
fmt.Println("[Info] IPv6 UDP Traceroute is not supported right now.")
os.Exit(0)
}
ip = util.DomainLookUp(domain, "4", *dot, *jsonPrint)
} else {
if *ipv6Only {
ip = util.DomainLookUp(domain, "6", *dot, *jsonPrint)
} else if *ipv4Only {
ip = util.DomainLookUp(domain, "4", *dot, *jsonPrint)
} else {
if *ipv6Only {
ip = util.DomainLookUp(domain, "6", *dot, *jsonPrint)
} else if *ipv4Only {
ip = util.DomainLookUp(domain, "4", *dot, *jsonPrint)
} else {
ip = util.DomainLookUp(domain, "all", *dot, *jsonPrint)
}
ip = util.DomainLookUp(domain, "all", *dot, *jsonPrint)
}
}()
wg.Wait()
}
//}()
//
//wg.Wait()
if *srcDev != "" {
dev, _ := net.InterfaceByName(*srcDev)
@@ -198,7 +202,7 @@ func Excute() {
}
if !*jsonPrint {
printer.PrintTraceRouteNav(ip, domain, *dataOrigin, *maxHops)
printer.PrintTraceRouteNav(ip, domain, *dataOrigin, *maxHops, *packetSize)
}
var m trace.Method = ""

View File

@@ -2,17 +2,15 @@ package fastTrace
import (
"fmt"
"github.com/xgadget-lab/nexttrace/util"
"log"
"os"
"os/signal"
"time"
"github.com/xgadget-lab/nexttrace/ipgeo"
"github.com/xgadget-lab/nexttrace/printer"
"github.com/xgadget-lab/nexttrace/trace"
"github.com/xgadget-lab/nexttrace/tracelog"
"github.com/xgadget-lab/nexttrace/util"
"github.com/xgadget-lab/nexttrace/wshandle"
"log"
"os"
"os/signal"
)
func (f *FastTracer) tracert_v6(location string, ispCollection ISPCollection) {
@@ -31,19 +29,25 @@ func (f *FastTracer) tracert_v6(location string, ispCollection ISPCollection) {
log.SetFlags(0)
fmt.Printf("%s『%s %s 』%s\n", printer.YELLOW_PREFIX, location, ispCollection.ISPName, printer.RESET_PREFIX)
log.Printf("『%s %s 』\n", location, ispCollection.ISPName)
fmt.Printf("traceroute to %s, 30 hops max, 32 byte packets\n", ispCollection.IPv6)
log.Printf("traceroute to %s, 30 hops max, 32 byte packets\n", ispCollection.IPv6)
fmt.Printf("traceroute to %s, %d hops max, %d byte packets\n", ispCollection.IPv6, f.ParamsFastTrace.MaxHops, f.ParamsFastTrace.PktSize)
log.Printf("traceroute to %s, %d hops max, %d byte packets\n", ispCollection.IPv6, f.ParamsFastTrace.MaxHops, f.ParamsFastTrace.PktSize)
ip := util.DomainLookUp(ispCollection.IP, "6", "", true)
var conf = trace.Config{
BeginHop: 1,
BeginHop: f.ParamsFastTrace.BeginHop,
DestIP: ip,
DestPort: 80,
MaxHops: 30,
MaxHops: f.ParamsFastTrace.MaxHops,
NumMeasurements: 3,
ParallelRequests: 18,
RDns: true,
RDns: f.ParamsFastTrace.RDns,
AlwaysWaitRDNS: f.ParamsFastTrace.AlwaysWaitRDNS,
PacketInterval: 100,
TTLInterval: 500,
IPGeoSource: ipgeo.GetSource("LeoMoeAPI"),
Timeout: 1 * time.Second,
Timeout: f.ParamsFastTrace.Timeout,
SrcAddr: f.ParamsFastTrace.SrcAddr,
PktSize: f.ParamsFastTrace.PktSize,
Lang: f.ParamsFastTrace.Lang,
}
if oe {

View File

@@ -2,18 +2,17 @@ package fastTrace
import (
"fmt"
"github.com/xgadget-lab/nexttrace/ipgeo"
"github.com/xgadget-lab/nexttrace/printer"
"github.com/xgadget-lab/nexttrace/trace"
"github.com/xgadget-lab/nexttrace/tracelog"
"github.com/xgadget-lab/nexttrace/util"
"github.com/xgadget-lab/nexttrace/wshandle"
"log"
"net"
"os"
"os/signal"
"time"
"github.com/xgadget-lab/nexttrace/ipgeo"
"github.com/xgadget-lab/nexttrace/printer"
"github.com/xgadget-lab/nexttrace/trace"
"github.com/xgadget-lab/nexttrace/tracelog"
"github.com/xgadget-lab/nexttrace/wshandle"
)
type FastTracer struct {
@@ -30,6 +29,7 @@ type ParamsFastTrace struct {
AlwaysWaitRDNS bool
Lang string
PktSize int
Timeout time.Duration
}
var oe = false
@@ -50,8 +50,8 @@ func (f *FastTracer) tracert(location string, ispCollection ISPCollection) {
log.SetFlags(0)
fmt.Printf("%s『%s %s 』%s\n", printer.YELLOW_PREFIX, location, ispCollection.ISPName, printer.RESET_PREFIX)
log.Printf("『%s %s 』\n", location, ispCollection.ISPName)
fmt.Printf("traceroute to %s, 30 hops max, 32 byte packets\n", ispCollection.IP)
log.Printf("traceroute to %s, 30 hops max, 32 byte packets\n", ispCollection.IP)
fmt.Printf("traceroute to %s, %d hops max, %d byte packets\n", ispCollection.IP, f.ParamsFastTrace.MaxHops, f.ParamsFastTrace.PktSize)
log.Printf("traceroute to %s, %d hops max, %d byte packets\n", ispCollection.IP, f.ParamsFastTrace.MaxHops, f.ParamsFastTrace.PktSize)
ip := util.DomainLookUp(ispCollection.IP, "4", "", true)
var conf = trace.Config{
BeginHop: f.ParamsFastTrace.BeginHop,
@@ -65,7 +65,7 @@ func (f *FastTracer) tracert(location string, ispCollection ISPCollection) {
PacketInterval: 100,
TTLInterval: 500,
IPGeoSource: ipgeo.GetSource("LeoMoeAPI"),
Timeout: 1 * time.Second,
Timeout: f.ParamsFastTrace.Timeout,
SrcAddr: f.ParamsFastTrace.SrcAddr,
PktSize: f.ParamsFastTrace.PktSize,
Lang: f.ParamsFastTrace.Lang,

View File

@@ -63,13 +63,13 @@ func PluginCopyRight() {
)
}
func PrintTraceRouteNav(ip net.IP, domain string, dataOrigin string, maxHops int) {
func PrintTraceRouteNav(ip net.IP, domain string, dataOrigin string, maxHops int, packetSize int) {
fmt.Println("IP Geo Data Provider: " + dataOrigin)
if ip.String() == domain {
fmt.Printf("traceroute to %s, %d hops max, 32 byte packets\n", ip.String(), maxHops)
fmt.Printf("traceroute to %s, %d hops max, %d bytes packets\n", ip.String(), maxHops, packetSize)
} else {
fmt.Printf("traceroute to %s (%s), %d hops max, 32 byte packets\n", ip.String(), domain, maxHops)
fmt.Printf("traceroute to %s (%s), %d hops max, %d bytes packets\n", ip.String(), domain, maxHops, packetSize)
}
}

View File

@@ -26,7 +26,6 @@ func GetMapUrl(r string) (string, error) {
}
u := url.URL{Scheme: "https", Host: fastIp + ":" + port, Path: "/tracemap/api"}
tracemapUrl := u.String()
tracemapUrl = "https://api.leo.moe/tracemap/api"
client := &http.Client{
Timeout: 5 * time.Second,