Skip to content

Commit 23d20de

Browse files
committed
fix bug:fasttrace也进行nslookup
1 parent bf4ec99 commit 23d20de

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

fast_trace/fast_trace ipv6.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package fastTrace
22

33
import (
44
"fmt"
5+
"github.com/xgadget-lab/nexttrace/util"
56
"log"
6-
"net"
77
"os"
88
"os/signal"
99
"time"
@@ -33,7 +33,7 @@ func (f *FastTracer) tracert_v6(location string, ispCollection ISPCollection) {
3333
log.Printf("『%s %s 』\n", location, ispCollection.ISPName)
3434
fmt.Printf("traceroute to %s, 30 hops max, 32 byte packets\n", ispCollection.IPv6)
3535
log.Printf("traceroute to %s, 30 hops max, 32 byte packets\n", ispCollection.IPv6)
36-
ip := net.ParseIP(ispCollection.IPv6)
36+
ip := util.DomainLookUp(ispCollection.IP, false, "", true)
3737
var conf = trace.Config{
3838
BeginHop: 1,
3939
DestIP: ip,

fast_trace/fast_trace.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package fastTrace
22

33
import (
44
"fmt"
5+
"github.com/xgadget-lab/nexttrace/util"
56
"log"
6-
"net"
77
"os"
88
"os/signal"
99
"time"
@@ -39,7 +39,7 @@ func (f *FastTracer) tracert(location string, ispCollection ISPCollection) {
3939
log.Printf("『%s %s 』\n", location, ispCollection.ISPName)
4040
fmt.Printf("traceroute to %s, 30 hops max, 32 byte packets\n", ispCollection.IP)
4141
log.Printf("traceroute to %s, 30 hops max, 32 byte packets\n", ispCollection.IP)
42-
ip := net.ParseIP(ispCollection.IP)
42+
ip := util.DomainLookUp(ispCollection.IP, true, "", true)
4343
var conf = trace.Config{
4444
BeginHop: 1,
4545
DestIP: ip,

util/util.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func LocalIPPortv6(dstip net.IP) (net.IP, int) {
4646
}
4747

4848
func DomainLookUp(host string, ipv4Only bool, dotServer string, disableOutput bool) net.IP {
49+
// TODO: IPv4Only功能
4950
var (
5051
r *net.Resolver
5152
ips []net.IP
@@ -74,26 +75,24 @@ func DomainLookUp(host string, ipv4Only bool, dotServer string, disableOutput bo
7475
os.Exit(1)
7576
}
7677

77-
var ipv6Flag = false
78+
//var ipv6Flag = false
79+
//TODO: 此处代码暂无意义
80+
//if ipv6Flag {
81+
// fmt.Println("[Info] IPv6 UDP Traceroute is not supported right now.")
82+
// if len(ips) == 0 {
83+
// os.Exit(0)
84+
// }
85+
//}
7886

79-
if ipv6Flag {
80-
fmt.Println("[Info] IPv6 UDP Traceroute is not supported right now.")
81-
if len(ips) == 0 {
82-
os.Exit(0)
83-
}
84-
}
85-
86-
if len(ips) == 1 {
87+
if (len(ips) == 1) || (disableOutput) {
8788
return ips[0]
8889
} else {
8990
fmt.Println("Please Choose the IP You Want To TraceRoute")
9091
for i, ip := range ips {
91-
if !disableOutput {
92-
fmt.Fprintf(color.Output, "%s %s\n",
93-
color.New(color.FgHiYellow, color.Bold).Sprintf("%d.", i),
94-
color.New(color.FgWhite, color.Bold).Sprintf("%s", ip),
95-
)
96-
}
92+
fmt.Fprintf(color.Output, "%s %s\n",
93+
color.New(color.FgHiYellow, color.Bold).Sprintf("%d.", i),
94+
color.New(color.FgWhite, color.Bold).Sprintf("%s", ip),
95+
)
9796
}
9897
var index int
9998
fmt.Printf("Your Option: ")

0 commit comments

Comments
 (0)