Skip to content

Commit

Permalink
fix bug:fasttrace也进行nslookup
Browse files Browse the repository at this point in the history
  • Loading branch information
tsosunchia committed May 29, 2023
1 parent bf4ec99 commit 23d20de
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
4 changes: 2 additions & 2 deletions fast_trace/fast_trace ipv6.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package fastTrace

import (
"fmt"
"github.com/xgadget-lab/nexttrace/util"
"log"
"net"
"os"
"os/signal"
"time"
Expand Down Expand Up @@ -33,7 +33,7 @@ func (f *FastTracer) tracert_v6(location string, ispCollection ISPCollection) {
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)
ip := net.ParseIP(ispCollection.IPv6)
ip := util.DomainLookUp(ispCollection.IP, false, "", true)
var conf = trace.Config{
BeginHop: 1,
DestIP: ip,
Expand Down
4 changes: 2 additions & 2 deletions fast_trace/fast_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package fastTrace

import (
"fmt"
"github.com/xgadget-lab/nexttrace/util"
"log"
"net"
"os"
"os/signal"
"time"
Expand Down Expand Up @@ -39,7 +39,7 @@ func (f *FastTracer) tracert(location string, ispCollection ISPCollection) {
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)
ip := net.ParseIP(ispCollection.IP)
ip := util.DomainLookUp(ispCollection.IP, true, "", true)
var conf = trace.Config{
BeginHop: 1,
DestIP: ip,
Expand Down
29 changes: 14 additions & 15 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func LocalIPPortv6(dstip net.IP) (net.IP, int) {
}

func DomainLookUp(host string, ipv4Only bool, dotServer string, disableOutput bool) net.IP {
// TODO: IPv4Only功能
var (
r *net.Resolver
ips []net.IP
Expand Down Expand Up @@ -74,26 +75,24 @@ func DomainLookUp(host string, ipv4Only bool, dotServer string, disableOutput bo
os.Exit(1)
}

var ipv6Flag = false
//var ipv6Flag = false
//TODO: 此处代码暂无意义
//if ipv6Flag {
// fmt.Println("[Info] IPv6 UDP Traceroute is not supported right now.")
// if len(ips) == 0 {
// os.Exit(0)
// }
//}

if ipv6Flag {
fmt.Println("[Info] IPv6 UDP Traceroute is not supported right now.")
if len(ips) == 0 {
os.Exit(0)
}
}

if len(ips) == 1 {
if (len(ips) == 1) || (disableOutput) {
return ips[0]
} else {
fmt.Println("Please Choose the IP You Want To TraceRoute")
for i, ip := range ips {
if !disableOutput {
fmt.Fprintf(color.Output, "%s %s\n",
color.New(color.FgHiYellow, color.Bold).Sprintf("%d.", i),
color.New(color.FgWhite, color.Bold).Sprintf("%s", ip),
)
}
fmt.Fprintf(color.Output, "%s %s\n",
color.New(color.FgHiYellow, color.Bold).Sprintf("%d.", i),
color.New(color.FgWhite, color.Bold).Sprintf("%s", ip),
)
}
var index int
fmt.Printf("Your Option: ")
Expand Down

0 comments on commit 23d20de

Please sign in to comment.