Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #20 from OwO-Network/tcpTrace-ipv6
Browse files Browse the repository at this point in the history
try: add ipv6 tcp trace support
  • Loading branch information
tsosunchia authored Feb 15, 2023
2 parents 267171f + d476966 commit 9c40f1f
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 90 deletions.
40 changes: 24 additions & 16 deletions fast_trace/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ type BackBoneCollection struct {
CU169 ISPCollection
CU9929 ISPCollection
CM ISPCollection
CMIN2 ISPCollection
CMIN2 ISPCollection
EDU ISPCollection
CST ISPCollection
}

type ISPCollection struct {
ISPName string
IP string
IPv6 string
}

const (
Expand All @@ -42,21 +43,22 @@ var TestIPsCollection = AllLocationCollection{
Guangzhou: Guangzhou,
Hangzhou: Hangzhou,
Hefei: Hefei,
Changsha: Changsha,
}

var Beijing = BackBoneCollection{
Location: "北京",
CT163: ISPCollection{
ISPName: CT163,
IP: "106.37.67.1",
IPv6: "240e:40:e002:1:a:3ee3:c00:0",
},

CU169: ISPCollection{
ISPName: CU169,
IP: "123.125.96.156",
IPv6: "2408:8000:1010:2::10",
},

CU9929: ISPCollection{
ISPName: CU9929,
IP: "218.105.131.125",
Expand All @@ -65,8 +67,9 @@ var Beijing = BackBoneCollection{
CM: ISPCollection{
ISPName: CM,
IP: "211.136.25.153",
IPv6: "2409:8000:3800:8::3",
},

CMIN2: ISPCollection{
ISPName: CMIN2,
IP: "223.70.155.55",
Expand All @@ -75,14 +78,16 @@ var Beijing = BackBoneCollection{
EDU: ISPCollection{
ISPName: EDU,
IP: "101.6.15.130",
IPv6: "2001:da8::666",
},
}

var Shanghai = BackBoneCollection{
Location: "上海",
CT163: ISPCollection{
ISPName: CT163,
IP: "101.226.28.198",
IP: "202.101.21.178",
IPv6: "240e:18:2:153::89",
},

CTCN2: ISPCollection{
Expand All @@ -93,18 +98,21 @@ var Shanghai = BackBoneCollection{
CU169: ISPCollection{
ISPName: CU169,
IP: "139.226.206.150",
IPv6: "2408:8000:9000:0:4000::437",
},

CU9929: ISPCollection{
ISPName: CU9929,
IP: "210.13.86.1",
IPv6: "2408:8120:2::d6",
},

CM: ISPCollection{
ISPName: CM,
IP: "120.204.34.85",
IPv6: "2409:801e:f0:1::4e1",
},

CMIN2: ISPCollection{
ISPName: CMIN2,
IP: "183.194.134.1",
Expand All @@ -113,24 +121,28 @@ var Shanghai = BackBoneCollection{
EDU: ISPCollection{
ISPName: EDU,
IP: "202.120.58.155",
IPv6: "2001:da8:8000:1:202:120:2:100",
},
}

var Guangzhou = BackBoneCollection{
Location: "广州",
CT163: ISPCollection{
ISPName: CT163,
IP: "106.37.67.1",
IP: "14.116.225.60",
IPv6: "240e:f9:8010::3:110:1",
},

CU169: ISPCollection{
ISPName: CU169,
IP: "157.18.0.22",
IPv6: "2408:8001:3161:4::1",
},

CM: ISPCollection{
ISPName: CM,
IP: "120.198.26.254",
IPv6: "2409:8055:3008:1116::150",
},
}

Expand All @@ -139,19 +151,23 @@ var Hangzhou = BackBoneCollection{
CT163: ISPCollection{
ISPName: CT163,
IP: "61.164.23.196",
IPv6: "240e:f3:c000:201::10",
},
CU169: ISPCollection{
ISPName: CU169,
IP: "60.12.244.1",
IPv6: "",
},
CM: ISPCollection{
ISPName: CM,
IP: "112.17.224.98",
IPv6: "2409:8028:840:2::11",
},
// 浙江大学 教育网
EDU: ISPCollection{
ISPName: EDU,
IP: "210.32.2.1",
IPv6: "2001:da8:e000:1::1",
},
}

Expand All @@ -161,19 +177,11 @@ var Hefei = BackBoneCollection{
EDU: ISPCollection{
ISPName: EDU,
IP: "202.38.64.1",
IPv6: "2001:da8:d805:ffff:2::1",
},
// 中国科学技术大学 科技网
CST: ISPCollection{
ISPName: "中国科学技术大学 科技网 AS7497",
IP: "210.72.22.2",
},
}

var Changsha = BackBoneCollection{
Location: "长沙",
// 中南大学 教育网
EDU: ISPCollection{
ISPName: EDU,
IP: "202.197.61.221",
},
}
136 changes: 136 additions & 0 deletions fast_trace/fast_trace ipv6.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package fastTrace

import (
"fmt"
"log"
"net"
"os"
"os/signal"
"time"

"github.com/OwO-Network/nexttrace-enhanced/ipgeo"
"github.com/OwO-Network/nexttrace-enhanced/printer"
"github.com/OwO-Network/nexttrace-enhanced/trace"
"github.com/OwO-Network/nexttrace-enhanced/wshandle"
//"github.com/xgadget-lab/nexttrace/tracelog"
)

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 {
return
}
defer fp.Close()

log.SetOutput(fp)
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)
ip := net.ParseIP(ispCollection.IPv6)
var conf = trace.Config{
BeginHop: 1,
DestIP: ip,
DestPort: 80,
MaxHops: 30,
NumMeasurements: 3,
ParallelRequests: 18,
RDns: true,
IPGeoSource: ipgeo.GetSource("LeoMoeAPI"),
Timeout: 1 * time.Second,
}
oe := false
if oe {
//conf.RealtimePrinter = tracelog.RealtimePrinter
} else {
conf.RealtimePrinter = printer.RealtimePrinter
}

_, err = trace.Traceroute(f.TracerouteMethod, conf)

if err != nil {
log.Fatal(err)
}

println()
}

func (f *FastTracer) testAll_v6() {
f.testCT_v6()
println()
f.testCU_v6()
println()
f.testCM_v6()
println()
f.testEDU_v6()
}

func (f *FastTracer) testCT_v6() {
f.tracert_v6(TestIPsCollection.Beijing.Location, TestIPsCollection.Beijing.CT163)
f.tracert_v6(TestIPsCollection.Shanghai.Location, TestIPsCollection.Shanghai.CT163)
f.tracert_v6(TestIPsCollection.Hangzhou.Location, TestIPsCollection.Hangzhou.CT163)
f.tracert_v6(TestIPsCollection.Guangzhou.Location, TestIPsCollection.Guangzhou.CT163)
}

func (f *FastTracer) testCU_v6() {
f.tracert_v6(TestIPsCollection.Beijing.Location, TestIPsCollection.Beijing.CU169)
f.tracert_v6(TestIPsCollection.Shanghai.Location, TestIPsCollection.Shanghai.CU169)
f.tracert_v6(TestIPsCollection.Shanghai.Location, TestIPsCollection.Shanghai.CU9929)
f.tracert_v6(TestIPsCollection.Guangzhou.Location, TestIPsCollection.Guangzhou.CU169)
}

func (f *FastTracer) testCM_v6() {
f.tracert_v6(TestIPsCollection.Beijing.Location, TestIPsCollection.Beijing.CM)
f.tracert_v6(TestIPsCollection.Shanghai.Location, TestIPsCollection.Shanghai.CM)
f.tracert_v6(TestIPsCollection.Hangzhou.Location, TestIPsCollection.Hangzhou.CM)
f.tracert_v6(TestIPsCollection.Guangzhou.Location, TestIPsCollection.Guangzhou.CM)
}

func (f *FastTracer) testEDU_v6() {
f.tracert_v6(TestIPsCollection.Beijing.Location, TestIPsCollection.Beijing.EDU)
f.tracert_v6(TestIPsCollection.Shanghai.Location, TestIPsCollection.Shanghai.EDU)
f.tracert_v6(TestIPsCollection.Hangzhou.Location, TestIPsCollection.Hangzhou.EDU)
}

func FastTestv6(tm bool, outEnable bool) {
var c string

//oe = outEnable

fmt.Println("您想测试哪些ISP的路由?\n1. 国内四网\n2. 电信\n3. 联通\n4. 移动\n5. 教育网")
fmt.Print("请选择选项:")
fmt.Scanln(&c)

ft := FastTracer{}

// 建立 WebSocket 连接
w := wshandle.New()
w.Interrupt = make(chan os.Signal, 1)
signal.Notify(w.Interrupt, os.Interrupt)
defer func() {
w.Conn.Close()
}()

if !tm {
ft.TracerouteMethod = trace.ICMPTrace
fmt.Println("您将默认使用ICMP协议进行路由跟踪,如果您想使用TCP SYN进行路由跟踪,可以加入 -T 参数")
} else {
ft.TracerouteMethod = trace.TCPTrace
}

switch c {
case "1":
ft.testAll_v6()
case "2":
ft.testCT_v6()
case "3":
ft.testCU_v6()
case "4":
ft.testCM_v6()
case "5":
ft.testEDU_v6()
default:
ft.testAll_v6()
}
}
10 changes: 10 additions & 0 deletions fast_trace/fast_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ func (f *FastTracer) testEDU() {
func FastTest(tm bool, srcDev string, srcAddr string) {
var c string

outEnable := false
fmt.Println("Hi,欢迎使用 Fast Trace 功能,请注意 Fast Trace 功能只适合新手使用\n因为国内网络复杂,我们设置的测试目标有限,建议普通用户自测以获得更加精准的路由情况")
fmt.Println("请您选择要测试的 IP 类型\n1. IPv4\n2. IPv6")
fmt.Print("请选择选项:")
fmt.Scanln(&c)
if c == "2" {
FastTestv6(tm, outEnable)
return
}

specificDev = srcDev
specificAddr = srcAddr

Expand Down
17 changes: 11 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,19 @@ func flagApply() string {
if target == "" {
printArgHelp()
}

if strings.Contains(target, "/") {
target = strings.Split(target, "/")[2]
}

if strings.Contains(target, "]") {
target = strings.Split(strings.Split(target, "]")[0], "[")[1]
} else if strings.Contains(target, ":") {
if strings.Count(target, ":") == 1 {
target = strings.Split(target, ":")[0]
}
}

return target
}

Expand Down Expand Up @@ -155,10 +155,15 @@ func main() {

var ip net.IP

if *tcpSYNFlag || *udpPackageFlag {
ip = util.DomainLookUp(domain, *dns_ip, true, false, *jsonEnable)
//if *tcpSYNFlag || *udpPackageFlag {
// ip = util.DomainLookUp(domain, *dns_ip, true, false, *jsonEnable)
//} else {
// ip = util.DomainLookUp(domain, *dns_ip, *ipv4Only, *ipv6Only, *jsonEnable)
//}
if *udpPackageFlag {
ip = util.DomainLookUp(domain, true)
} else {
ip = util.DomainLookUp(domain, *dns_ip, *ipv4Only, *ipv6Only, *jsonEnable)
ip = util.DomainLookUp(domain, false)
}

// if ip.To4() == nil && strings.ToUpper(*dataOrigin) == "LEOMOEAPI" {
Expand Down
9 changes: 9 additions & 0 deletions printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ import (

var dataOrigin string

const (
RED_PREFIX = "\033[1;31m"
GREEN_PREFIX = "\033[1;32m"
YELLOW_PREFIX = "\033[1;33m"
BLUE_PREFIX = "\033[1;34m"
CYAN_PREFIX = "\033[1;36m"
RESET_PREFIX = "\033[0m"
)

func TraceroutePrinter(res *trace.Result) {
for i, hop := range res.Hops {
fmt.Print(i + 1)
Expand Down
Loading

0 comments on commit 9c40f1f

Please sign in to comment.