diff --git a/cmd/cmd.go b/cmd/cmd.go index b50c570..3faf70e 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -35,7 +35,7 @@ func Excute() { tcp := parser.Flag("T", "tcp", &argparse.Options{Help: "Use TCP SYN for tracerouting (default port is 80)"}) udp := parser.Flag("U", "udp", &argparse.Options{Help: "Use UDP SYN for tracerouting (default port is 33494)"}) fast_trace := parser.Flag("F", "fast-trace", &argparse.Options{Help: "One-Key Fast Trace to China ISPs"}) - port := parser.Int("p", "port", &argparse.Options{Help: "Set the destination port to use. With default of 80 for \"tcp\", 33494 for \"udp\""}) + port := parser.Int("p", "port", &argparse.Options{Help: "Set the destination port to use. With default of 80 for \"tcp\", 33494 for \"udp\"", Default: 80}) numMeasurements := parser.Int("q", "queries", &argparse.Options{Default: 3, Help: "Set the number of probes per each hop"}) parallelRequests := parser.Int("", "parallel-requests", &argparse.Options{Default: 18, Help: "Set ParallelRequests number. It should be 1 when there is a multi-routing"}) maxHops := parser.Int("m", "max-hops", &argparse.Options{Default: 30, Help: "Set the max number of hops (max TTL to be reached)"}) @@ -96,16 +96,28 @@ func Excute() { os.Exit(0) } + if !*tcp && *port == 80 { + *port = 33494 + } + domain := *str - if *port == 0 { - *port = 80 + var m trace.Method + + switch { + case *tcp: + m = trace.TCPTrace + case *udp: + m = trace.UDPTrace + default: + m = trace.ICMPTrace } if *fast_trace || *file != "" { var paramsFastTrace = fastTrace.ParamsFastTrace{ SrcDev: *srcDev, SrcAddr: *srcAddr, + DestPort: *port, BeginHop: *beginHop, MaxHops: *maxHops, RDns: !*noRdns, @@ -118,7 +130,7 @@ func Excute() { Dot: *dot, } - fastTrace.FastTest(*tcp, *output, paramsFastTrace) + fastTrace.FastTest(m, *output, paramsFastTrace) if *output { fmt.Println("您的追踪日志已经存放在 /tmp/trace.log 中") } @@ -240,25 +252,10 @@ func Excute() { } } - var m trace.Method - - switch { - case *tcp: - m = trace.TCPTrace - case *udp: - m = trace.UDPTrace - default: - m = trace.ICMPTrace - } - if !*jsonPrint { printer.PrintTraceRouteNav(ip, domain, *dataOrigin, *maxHops, *packetSize, *srcAddr, string(m)) } - if !*tcp && *port == 80 { - *port = 33494 - } - util.DestIP = ip.String() var conf = trace.Config{ DN42: *dn42, diff --git a/fast_trace/fast_trace ipv6.go b/fast_trace/fast_trace ipv6.go index 97dc60a..6d31473 100644 --- a/fast_trace/fast_trace ipv6.go +++ b/fast_trace/fast_trace ipv6.go @@ -29,7 +29,7 @@ func (f *FastTracer) tracert_v6(location string, ispCollection ISPCollection) { var conf = trace.Config{ BeginHop: f.ParamsFastTrace.BeginHop, DestIP: ip, - DestPort: 80, + DestPort: f.ParamsFastTrace.DestPort, MaxHops: f.ParamsFastTrace.MaxHops, NumMeasurements: 3, ParallelRequests: 18, @@ -124,7 +124,7 @@ func (f *FastTracer) testFast_v6() { //f.tracert_v6(TestIPsCollection.Beijing.Location, TestIPsCollection.Beijing.CST) } -func FastTestv6(tm bool, outEnable bool, paramsFastTrace ParamsFastTrace) { +func FastTestv6(traceMode trace.Method, outEnable bool, paramsFastTrace ParamsFastTrace) { var c string oe = outEnable @@ -148,11 +148,14 @@ func FastTestv6(tm bool, outEnable bool, paramsFastTrace ParamsFastTrace) { w.Conn.Close() }() - if !tm { + switch traceMode { + case trace.ICMPTrace: ft.TracerouteMethod = trace.ICMPTrace - fmt.Println("您将默认使用ICMP协议进行路由跟踪,如果您想使用TCP SYN进行路由跟踪,可以加入 -T 参数") - } else { + case trace.TCPTrace: ft.TracerouteMethod = trace.TCPTrace + case trace.UDPTrace: + fmt.Println("[Info] IPv6 UDP Traceroute is not supported right now.") + os.Exit(0) } switch c { diff --git a/fast_trace/fast_trace.go b/fast_trace/fast_trace.go index 6c90e98..3e9f134 100644 --- a/fast_trace/fast_trace.go +++ b/fast_trace/fast_trace.go @@ -26,6 +26,7 @@ type FastTracer struct { type ParamsFastTrace struct { SrcDev string SrcAddr string + DestPort int BeginHop int MaxHops int RDns bool @@ -58,7 +59,7 @@ func (f *FastTracer) tracert(location string, ispCollection ISPCollection) { var conf = trace.Config{ BeginHop: f.ParamsFastTrace.BeginHop, DestIP: ip, - DestPort: 80, + DestPort: f.ParamsFastTrace.DestPort, MaxHops: f.ParamsFastTrace.MaxHops, NumMeasurements: 3, ParallelRequests: 18, @@ -103,13 +104,13 @@ func (f *FastTracer) tracert(location string, ispCollection ISPCollection) { fmt.Println() } -func FastTest(tm bool, outEnable bool, paramsFastTrace ParamsFastTrace) { +func FastTest(traceMode trace.Method, outEnable bool, paramsFastTrace ParamsFastTrace) { // tm means tcp mode var c string oe = outEnable if paramsFastTrace.File != "" { - testFile(paramsFastTrace, tm) + testFile(paramsFastTrace, traceMode) return } @@ -139,7 +140,7 @@ func FastTest(tm bool, outEnable bool, paramsFastTrace ParamsFastTrace) { } } } - FastTestv6(tm, outEnable, paramsFastTrace) + FastTestv6(traceMode, outEnable, paramsFastTrace) return } if paramsFastTrace.SrcDev != "" { @@ -180,11 +181,13 @@ func FastTest(tm bool, outEnable bool, paramsFastTrace ParamsFastTrace) { w.Conn.Close() }() - if !tm { + switch traceMode { + case trace.ICMPTrace: ft.TracerouteMethod = trace.ICMPTrace - fmt.Println("您将默认使用ICMP协议进行路由跟踪,如果您想使用TCP SYN进行路由跟踪,可以加入 -T 参数") - } else { + case trace.TCPTrace: ft.TracerouteMethod = trace.TCPTrace + case trace.UDPTrace: + ft.TracerouteMethod = trace.UDPTrace } switch c { @@ -205,7 +208,7 @@ func FastTest(tm bool, outEnable bool, paramsFastTrace ParamsFastTrace) { } } -func testFile(paramsFastTrace ParamsFastTrace, tm bool) { +func testFile(paramsFastTrace ParamsFastTrace, traceMode trace.Method) { // 建立 WebSocket 连接 w := wshandle.New() w.Interrupt = make(chan os.Signal, 1) @@ -215,11 +218,13 @@ func testFile(paramsFastTrace ParamsFastTrace, tm bool) { }() var tracerouteMethod trace.Method - if !tm { + switch traceMode { + case trace.ICMPTrace: tracerouteMethod = trace.ICMPTrace - fmt.Println("您将默认使用ICMP协议进行路由跟踪,如果您想使用TCP SYN进行路由跟踪,可以加入 -T 参数") - } else { + case trace.TCPTrace: tracerouteMethod = trace.TCPTrace + case trace.UDPTrace: + tracerouteMethod = trace.UDPTrace } filePath := paramsFastTrace.File @@ -331,7 +336,7 @@ func testFile(paramsFastTrace ParamsFastTrace, tm bool) { var conf = trace.Config{ BeginHop: paramsFastTrace.BeginHop, DestIP: net.ParseIP(ip.Ip), - DestPort: 80, + DestPort: paramsFastTrace.DestPort, MaxHops: paramsFastTrace.MaxHops, NumMeasurements: 3, ParallelRequests: 18,