Skip to content

Commit

Permalink
Merge pull request #240 from nxtrace/main
Browse files Browse the repository at this point in the history
SYNC
  • Loading branch information
tsosunchia authored May 13, 2024
2 parents e128fe1 + 6937b54 commit 3916929
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 65 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,12 @@ This software is still in the early stages of development and may have many flaw

[https://github.com/nxtrace/nexttracewebapi](https://github.com/nxtrace/nexttracewebapi)

## NextTraceroute

`NextTraceroute` is a root-free Android route tracing application that defaults to using the `NextTrace API`, developed by @surfaceocean.

[https://github.com/nxtrace/NextTraceroute](https://github.com/nxtrace/NextTraceroute)

## LeoMoeAPI Credits

NextTrace focuses on Golang Traceroute implementations, and its LeoMoeAPI geolocation information is not supported by raw data, so a commercial version is not possible.
Expand Down
6 changes: 6 additions & 0 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,12 @@ nexttrace --pow-provider sakura

[https://github.com/nxtrace/nexttracewebapi](https://github.com/nxtrace/nexttracewebapi)

## NextTraceroute

`NextTraceroute`,一款默认使用`NextTrace API`的免`root`安卓版路由跟踪应用,由 @surfaceocean 开发。

[https://github.com/nxtrace/NextTraceroute](https://github.com/nxtrace/NextTraceroute)

## Credits

[IPInfo](https://ipinfo.io) 无偿提供了本项目大部分数据支持
Expand Down
4 changes: 2 additions & 2 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func Excute() {
}
// DOMAIN处理结束

capabilities_check()
capabilitiesCheck()
// return

var ip net.IP
Expand Down Expand Up @@ -357,7 +357,7 @@ func Excute() {
}
}

func capabilities_check() {
func capabilitiesCheck() {

// Windows 判断放在前面,防止遇到一些奇奇怪怪的问题
if runtime.GOOS == "windows" {
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/stretchr/testify v1.9.0
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635
github.com/tsosunchia/powclient v0.1.4
golang.org/x/net v0.24.0
golang.org/x/net v0.25.0
golang.org/x/sync v0.7.0
)

Expand All @@ -22,7 +22,7 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
Expand All @@ -32,19 +32,19 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/text v0.15.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)

require (
github.com/fatih/color v1.16.0
github.com/fatih/color v1.17.0
github.com/gorilla/websocket v1.5.1
github.com/lionsoul2014/ip2region v2.11.2+incompatible
github.com/rodaine/table v1.2.0
github.com/tidwall/gjson v1.17.1
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/sys v0.20.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
Expand Down Expand Up @@ -37,8 +37,8 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/oschwald/maxminddb-golang v1.12.0 h1:9FnTOD0YOhP7DGxGsq4glzpGy5+w7pq50AS6wALUMYs=
github.com/oschwald/maxminddb-golang v1.12.0/go.mod h1:q0Nob5lTCqyQ8WT6FYgS1L7PXKVVbgiymefNwIjPzgY=
github.com/pelletier/go-toml/v2 v2.2.1 h1:9TA9+T8+8CUCO2+WYnDLCgrYi9+omqKXyjDtosvtEhg=
github.com/pelletier/go-toml/v2 v2.2.1/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down Expand Up @@ -88,26 +88,26 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f h1:99ci1mjWVBWwJiEKYY6jWa4d2nTQVIEhZIptnrVb1XY=
golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
8 changes: 4 additions & 4 deletions ipgeo/ipgeo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import (
// )

func TestXxx(t *testing.T) {
const ID_FIXED_HEADER = "10"
const IdFixedHeader = "10"
var processID = fmt.Sprintf("%07b", os.Getpid()&0x7f) //取进程ID的前7位
var ttl = fmt.Sprintf("%06b", 95) //取TTL的后6位
fmt.Println(os.Getpid()&0x7f, 95)

var parity int
id := ID_FIXED_HEADER + processID + ttl
id := IdFixedHeader + processID + ttl
for _, c := range id {
if c == '1' {
parity++
Expand All @@ -33,8 +33,8 @@ func TestXxx(t *testing.T) {
} else {
id += "0"
}
process_id, ttl_r, _ := reverseID(id)
log.Println(process_id, ttl_r)
processId, ttlR, _ := reverseID(id)
log.Println(processId, ttlR)
}

func TestFilter(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions ipgeo/ipinfoLocal.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ func IPInfoLocal(ip string, _ time.Duration, _ string, _ bool) (*IPGeoData, erro
return &IPGeoData{}, errors.New("no results")
}
recordMap := record.(map[string]interface{})
country_name := recordMap["country_name"].(string)
countryName := recordMap["country_name"].(string)
prov := ""
if recordMap["country"].(string) == "HK" {
country_name = "China"
countryName = "China"
prov = "Hong Kong"
}
if recordMap["country"].(string) == "TW" {
country_name = "China"
countryName = "China"
prov = "Taiwan"
}
return &IPGeoData{
Asnumber: strings.TrimPrefix(recordMap["asn"].(string), "AS"),
Country: country_name,
Country: countryName,
City: "",
Prov: prov,
Owner: recordMap["as_name"].(string),
Expand Down
24 changes: 15 additions & 9 deletions trace/icmp_ipv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ func (t *ICMPTracer) listenICMP() {
continue
}
ttl := int64(binary.BigEndian.Uint16(msg.Msg[34:36]))
packet_id := strconv.FormatInt(int64(binary.BigEndian.Uint16(msg.Msg[32:34])), 2)
if process_id, _, err := reverseID(packet_id); err == nil {
if process_id == int64(os.Getpid()&0x7f) {
packetId := strconv.FormatInt(int64(binary.BigEndian.Uint16(msg.Msg[32:34])), 2)
if processId, _, err := reverseID(packetId); err == nil {
if processId == int64(os.Getpid()&0x7f) {
dstip := net.IP(msg.Msg[24:28])
if dstip.Equal(t.DestIP) || dstip.Equal(net.IPv4zero) {
// 匹配再继续解析包,否则直接丢弃
Expand Down Expand Up @@ -202,13 +202,13 @@ func (t *ICMPTracer) handleICMPMessage(msg ReceivedMessage, icmpType int8, data
}
}

func gernerateID(ttl_int int) int {
const ID_FIXED_HEADER = "10"
func gernerateID(ttlInt int) int {
const IdFixedHeader = "10"
var processID = fmt.Sprintf("%07b", os.Getpid()&0x7f) //取进程ID的前7位
var ttl = fmt.Sprintf("%06b", ttl_int) //取TTL的后6位
var ttl = fmt.Sprintf("%06b", ttlInt) //取TTL的后6位

var parity int
id := ID_FIXED_HEADER + processID + ttl
id := IdFixedHeader + processID + ttl
for _, c := range id {
if c == '1' {
parity++
Expand Down Expand Up @@ -286,7 +286,10 @@ func (t *ICMPTracer) send(ttl int) error {
},
}

ipv4.NewPacketConn(t.icmpListen).SetTTL(ttl)
err := ipv4.NewPacketConn(t.icmpListen).SetTTL(ttl)
if err != nil {
return err
}

wb, err := icmpHeader.Marshal(nil)
if err != nil {
Expand Down Expand Up @@ -328,7 +331,10 @@ func (t *ICMPTracer) send(ttl int) error {

t.fetchLock.Lock()
defer t.fetchLock.Unlock()
h.fetchIPData(t.Config)
err := h.fetchIPData(t.Config)
if err != nil {
return err
}

t.res.add(h)
case <-time.After(t.Timeout):
Expand Down
16 changes: 11 additions & 5 deletions trace/icmp_ipv6.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ func (t *ICMPTracerv6) listenICMP() {

}
ttl := int64(binary.BigEndian.Uint16(msg.Msg[54:56]))
packet_id := strconv.FormatInt(int64(binary.BigEndian.Uint16(msg.Msg[52:54])), 2)
if process_id, _, err := reverseID(packet_id); err == nil {
if process_id == int64(os.Getpid()&0x7f) {
packetId := strconv.FormatInt(int64(binary.BigEndian.Uint16(msg.Msg[52:54])), 2)
if processId, _, err := reverseID(packetId); err == nil {
if processId == int64(os.Getpid()&0x7f) {
dstip := net.IP(msg.Msg[32:48])
// 无效包本地环回包
if dstip.String() == "::" {
Expand Down Expand Up @@ -282,7 +282,10 @@ func (t *ICMPTracerv6) send(ttl int) error {
p := ipv6.NewPacketConn(t.icmpListen)

icmpHeader.Body.(*icmp.Echo).Seq = ttl
p.SetHopLimit(ttl)
err := p.SetHopLimit(ttl)
if err != nil {
return err
}

wb, err := icmpHeader.Marshal(nil)
if err != nil {
Expand Down Expand Up @@ -324,7 +327,10 @@ func (t *ICMPTracerv6) send(ttl int) error {

t.fetchLock.Lock()
defer t.fetchLock.Unlock()
h.fetchIPData(t.Config)
err := h.fetchIPData(t.Config)
if err != nil {
return err
}

t.res.add(h)

Expand Down
12 changes: 9 additions & 3 deletions trace/internal/icmp_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func ListenICMP(network string, laddr string) (net.PacketConn, error) {
proto = syscall.IPPROTO_ICMPV6
}

var ifIndex int = -1
var ifIndex = -1
if laddr != "" {
la := net.ParseIP(laddr)
if ifaces, err := net.Interfaces(); err == nil {
Expand Down Expand Up @@ -70,11 +70,17 @@ func ListenICMP(network string, laddr string) (net.PacketConn, error) {
if ifIndex != -1 {
if proto == syscall.IPPROTO_ICMP {
return c.Control(func(fd uintptr) {
syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IP, syscall.IP_BOUND_IF, ifIndex)
err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IP, syscall.IP_BOUND_IF, ifIndex)
if err != nil {
return
}
})
} else {
return c.Control(func(fd uintptr) {
syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IPV6, syscall.IPV6_BOUND_IF, ifIndex)
err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IPV6, syscall.IPV6_BOUND_IF, ifIndex)
if err != nil {
return
}
})
}
}
Expand Down
5 changes: 4 additions & 1 deletion trace/tcp_ipv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,10 @@ func (t *TCPTracer) send(ttl int) error {

t.fetchLock.Lock()
defer t.fetchLock.Unlock()
h.fetchIPData(t.Config)
err := h.fetchIPData(t.Config)
if err != nil {
return err
}

t.res.add(h)

Expand Down
5 changes: 4 additions & 1 deletion trace/tcp_ipv6.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,10 @@ func (t *TCPTracerv6) send(ttl int) error {
return err
}

ipv6.NewPacketConn(t.tcp).SetHopLimit(ttl)
err = ipv6.NewPacketConn(t.tcp).SetHopLimit(ttl)
if err != nil {
return err
}
if err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion trace/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,10 @@ func (t *UDPTracer) send(ttl int) error {

t.fetchLock.Lock()
defer t.fetchLock.Unlock()
h.fetchIPData(t.Config)
err := h.fetchIPData(t.Config)
if err != nil {
return err
}

t.res.add(h)

Expand Down
Loading

0 comments on commit 3916929

Please sign in to comment.