fix bugs:ipv6下fasttrace异常退出的问题

This commit is contained in:
tsosunchia
2023-06-04 05:06:23 +08:00
parent dcce91614f
commit 2c86f86204
5 changed files with 25 additions and 16 deletions

View File

@@ -13,6 +13,8 @@ import (
"os/signal"
)
var pFastTracer ParamsFastTrace
func (f *FastTracer) tracert_v6(location string, ispCollection ISPCollection) {
fp, err := os.OpenFile("/tmp/trace.log", os.O_CREATE|os.O_APPEND|os.O_RDWR, os.ModePerm)
if err != nil {
@@ -29,25 +31,24 @@ 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, %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)
fmt.Printf("traceroute to %s, %d hops max, %d byte packets\n", ispCollection.IPv6, pFastTracer.MaxHops, pFastTracer.PktSize)
log.Printf("traceroute to %s, %d hops max, %d byte packets\n", ispCollection.IPv6, pFastTracer.MaxHops, pFastTracer.PktSize)
ip := util.DomainLookUp(ispCollection.IPv6, "6", "", true)
var conf = trace.Config{
BeginHop: f.ParamsFastTrace.BeginHop,
BeginHop: pFastTracer.BeginHop,
DestIP: ip,
DestPort: 80,
MaxHops: f.ParamsFastTrace.MaxHops,
MaxHops: pFastTracer.MaxHops,
NumMeasurements: 3,
ParallelRequests: 18,
RDns: f.ParamsFastTrace.RDns,
AlwaysWaitRDNS: f.ParamsFastTrace.AlwaysWaitRDNS,
RDns: pFastTracer.RDns,
AlwaysWaitRDNS: pFastTracer.AlwaysWaitRDNS,
PacketInterval: 100,
TTLInterval: 500,
IPGeoSource: ipgeo.GetSource("LeoMoeAPI"),
Timeout: f.ParamsFastTrace.Timeout,
SrcAddr: f.ParamsFastTrace.SrcAddr,
PktSize: f.ParamsFastTrace.PktSize,
Lang: f.ParamsFastTrace.Lang,
Timeout: pFastTracer.Timeout,
PktSize: pFastTracer.PktSize,
Lang: pFastTracer.Lang,
}
if oe {
@@ -102,10 +103,11 @@ func (f *FastTracer) testEDU_v6() {
f.tracert_v6(TestIPsCollection.Hangzhou.Location, TestIPsCollection.Hangzhou.EDU)
}
func FastTestv6(tm bool, outEnable bool) {
func FastTestv6(tm bool, outEnable bool, paramsFastTrace ParamsFastTrace) {
var c string
oe = outEnable
pFastTracer = paramsFastTrace
fmt.Println("您想测试哪些ISP的路由\n1. 国内四网\n2. 电信\n3. 联通\n4. 移动\n5. 教育网")
fmt.Print("请选择选项:")

View File

@@ -97,7 +97,7 @@ func FastTest(tm bool, outEnable bool, paramsFastTrace ParamsFastTrace) {
c = "1"
}
if c == "2" {
FastTestv6(tm, outEnable)
FastTestv6(tm, outEnable, paramsFastTrace)
return
}

View File

@@ -31,7 +31,7 @@ func TestTrace(t *testing.T) {
}()
fmt.Println("TCP v4")
ft.TracerouteMethod = trace.TCPTrace
ft.tracert(TestIPsCollection.Beijing.Location, TestIPsCollection.Beijing.EDU)
//ft.tracert(TestIPsCollection.Beijing.Location, TestIPsCollection.Beijing.EDU)
//fmt.Println("TCP v6")
//ft.tracert_v6(TestIPsCollection.Beijing.Location, TestIPsCollection.Beijing.EDU)
//fmt.Println("ICMP v4")

View File

@@ -11,3 +11,10 @@ func TestDNS(t *testing.T) {
ips, _ := resolver.LookupHost(context.Background(), "www.bing.com")
fmt.Println(ips)
}
func TestDomainLookUp(t *testing.T) {
ips := DomainLookUp("pek-4134.nexttrace-io-fasttrace-endpoint.win.", "all", "", false)
fmt.Println(ips)
ips = DomainLookUp("pek-4134.nexttrace-io-fasttrace-endpoint.win.", "4", "", false)
fmt.Println(ips)
}

View File

@@ -93,8 +93,8 @@ func DomainLookUp(host string, ipVersion string, dotServer string, disableOutput
default:
r = newUDPResolver()
}
ips_str, err := r.LookupHost(context.Background(), host)
for _, v := range ips_str {
ipsStr, err := r.LookupHost(context.Background(), host)
for _, v := range ipsStr {
ips = append(ips, net.ParseIP(v))
}
if err != nil {