mirror of
https://github.com/nxtrace/NTrace-core.git
synced 2025-08-12 06:26:39 +00:00
Compare commits
169 Commits
v0.1.2-bet
...
v0.1.5-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
efdfd9d612 | ||
|
|
016f06bafd | ||
|
|
1049986ebc | ||
|
|
80a75288d2 | ||
|
|
986b8ce300 | ||
|
|
ab774406ac | ||
|
|
9604b7befe | ||
|
|
dc6537005a | ||
|
|
839d227770 | ||
|
|
84e989e71b | ||
|
|
3b74b302cc | ||
|
|
9b0e58359f | ||
|
|
f0d7151144 | ||
|
|
3c65c29eff | ||
|
|
3aa4696fa9 | ||
|
|
b4abaffc7c | ||
|
|
c96fb4efa3 | ||
|
|
876de6bde1 | ||
|
|
7dbec0c7a1 | ||
|
|
d690f680f5 | ||
|
|
e96686013d | ||
|
|
6726b55fc9 | ||
|
|
9f29c75491 | ||
|
|
2f5bf3f195 | ||
|
|
5981e82ee3 | ||
|
|
80f7857a65 | ||
|
|
700d38de1c | ||
|
|
2dbf3f04a4 | ||
|
|
45df06ea80 | ||
|
|
98953048ce | ||
|
|
eddd4226b0 | ||
|
|
5afd9eb09e | ||
|
|
70006aaa13 | ||
|
|
497fb647c0 | ||
|
|
be8552c3cd | ||
|
|
f320fd6202 | ||
|
|
a42c5e3734 | ||
|
|
e6480c84e0 | ||
|
|
126115c04e | ||
|
|
ea7fd2af0f | ||
|
|
3fc81f4e71 | ||
|
|
0c2b77bd81 | ||
|
|
ac33c086c6 | ||
|
|
fadfdc87d4 | ||
|
|
eb77a2b69b | ||
|
|
02e6c6e1bf | ||
|
|
838af3b7a1 | ||
|
|
7cd16036a6 | ||
|
|
2ef4f61d7b | ||
|
|
688622738f | ||
|
|
83fe583f2a | ||
|
|
4b32594c17 | ||
|
|
927b6d4035 | ||
|
|
aa651f30cc | ||
|
|
ffec9a93cd | ||
|
|
59a744b3b5 | ||
|
|
9656dfe172 | ||
|
|
84c48dae99 | ||
|
|
4eaac372f6 | ||
|
|
c92d8a5172 | ||
|
|
acab410d4c | ||
|
|
858555fd86 | ||
|
|
31e419b199 | ||
|
|
1dddd43e67 | ||
|
|
4148d0d4b1 | ||
|
|
4f7977da8f | ||
|
|
cfc8034cb4 | ||
|
|
dbc0f87847 | ||
|
|
74a320898f | ||
|
|
329b3fdd6b | ||
|
|
3fb88f4cf4 | ||
|
|
1de84cac71 | ||
|
|
83d093f5aa | ||
|
|
8b03ca7a38 | ||
|
|
7a847bf0d5 | ||
|
|
11fe41611c | ||
|
|
71b24fb7a0 | ||
|
|
0b08e4b4a4 | ||
|
|
2608c05da1 | ||
|
|
314bdd0cce | ||
|
|
ea958059c6 | ||
|
|
b59c349264 | ||
|
|
030a487526 | ||
|
|
cac6d33fde | ||
|
|
1725a65827 | ||
|
|
4d886066a3 | ||
|
|
156043730d | ||
|
|
91ad3bc539 | ||
|
|
351da5f5a3 | ||
|
|
f8fc90d7a5 | ||
|
|
9c75635acc | ||
|
|
b20b27fd20 | ||
|
|
cfc1dfdfe5 | ||
|
|
97c4387af4 | ||
|
|
37b5202126 | ||
|
|
afb6a3e1df | ||
|
|
c9a3916cd0 | ||
|
|
89d56c437e | ||
|
|
6299dcd9a3 | ||
|
|
82f28a13f3 | ||
|
|
af732bc212 | ||
|
|
8d5f58bf15 | ||
|
|
8bd5654474 | ||
|
|
4de61823ee | ||
|
|
39ec016d0d | ||
|
|
67999411af | ||
|
|
7cc6b71727 | ||
|
|
16ba835537 | ||
|
|
1b7c3b8d0d | ||
|
|
bd47935a2d | ||
|
|
1f16001e4f | ||
|
|
f56e6cdba3 | ||
|
|
ecd3df8ee8 | ||
|
|
1658da1653 | ||
|
|
5110c9b990 | ||
|
|
aa446574f1 | ||
|
|
2016990629 | ||
|
|
e639b7b12d | ||
|
|
3cfe6598dd | ||
|
|
59193cae47 | ||
|
|
1def15e805 | ||
|
|
1950032371 | ||
|
|
f81a0b3da3 | ||
|
|
9e3d4186a1 | ||
|
|
4737669436 | ||
|
|
dbecfd880d | ||
|
|
a67a4bc559 | ||
|
|
077d72d5cd | ||
|
|
d45b5eb032 | ||
|
|
5fe1110ab3 | ||
|
|
812c953976 | ||
|
|
f89505ab87 | ||
|
|
640eb8c02d | ||
|
|
fc3462ff9e | ||
|
|
071a6b124a | ||
|
|
45a8cf21f6 | ||
|
|
1315efa4d2 | ||
|
|
c2bd51faab | ||
|
|
f1ce2bbb77 | ||
|
|
a18bf1889b | ||
|
|
12c93de8c5 | ||
|
|
8280b62881 | ||
|
|
608847b1cb | ||
|
|
b4838ba402 | ||
|
|
fbd70a8eb1 | ||
|
|
fd1632fccb | ||
|
|
4a725d2c48 | ||
|
|
96bb323f72 | ||
|
|
961c29e499 | ||
|
|
870d1f3b5a | ||
|
|
ebd435db53 | ||
|
|
53b2249ce5 | ||
|
|
7215a1e2b7 | ||
|
|
24b06d2fd7 | ||
|
|
f1f95dff29 | ||
|
|
0d9b8c8861 | ||
|
|
290524b502 | ||
|
|
905ef267f2 | ||
|
|
9720c19153 | ||
|
|
f2c494441b | ||
|
|
44aba64505 | ||
|
|
c0be6774c1 | ||
|
|
23693895e4 | ||
|
|
7edebf938b | ||
|
|
d4a176f864 | ||
|
|
69388c956e | ||
|
|
738ff949b1 | ||
|
|
b59f0eb9da | ||
|
|
24eedfa3fe |
@@ -5,7 +5,11 @@ set -e
|
||||
DIST_PREFIX="nexttrace"
|
||||
DEBUG_MODE=${2}
|
||||
TARGET_DIR="dist"
|
||||
PLATFORMS="darwin/amd64 darwin/arm64 linux/amd64 linux/arm64 linux/mips"
|
||||
PLATFORMS="darwin/amd64 darwin/arm64 linux/386 linux/amd64 linux/arm64 linux/mips openbsd/amd64 openbsd/arm64 freebsd/amd64 freebsd/arm64"
|
||||
|
||||
BUILD_VERSION="$(git describe --tags --always)"
|
||||
BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
|
||||
COMMIT_SHA1="$(git rev-parse --short HEAD)"
|
||||
|
||||
rm -rf ${TARGET_DIR}
|
||||
mkdir ${TARGET_DIR}
|
||||
@@ -21,16 +25,36 @@ for pl in ${PLATFORMS}; do
|
||||
echo "build => ${TARGET}"
|
||||
if [ "${DEBUG_MODE}" == "debug" ]; then
|
||||
go build -trimpath -gcflags "all=-N -l" -o ${TARGET} \
|
||||
-ldflags "-X 'main.version=${BUILD_VERSION}' \
|
||||
-X 'main.buildDate=${BUILD_DATE}' \
|
||||
-X 'main.commitID=${COMMIT_SHA1}'\
|
||||
-ldflags "-X 'github.com/xgadget-lab/nexttrace/printer.version=${BUILD_VERSION}' \
|
||||
-X 'github.com/xgadget-lab/nexttrace/printer.buildDate=${BUILD_DATE}' \
|
||||
-X 'github.com/xgadget-lab/nexttrace/printer.commitID=${COMMIT_SHA1}'\
|
||||
-w -s"
|
||||
else
|
||||
go build -trimpath -o ${TARGET} \
|
||||
-ldflags "-X 'main.version=${BUILD_VERSION}' \
|
||||
-X 'main.buildDate=${BUILD_DATE}' \
|
||||
-X 'main.commitID=${COMMIT_SHA1}'\
|
||||
-ldflags "-X 'github.com/xgadget-lab/nexttrace/printer.version=${BUILD_VERSION}' \
|
||||
-X 'github.com/xgadget-lab/nexttrace/printer.buildDate=${BUILD_DATE}' \
|
||||
-X 'github.com/xgadget-lab/nexttrace/printer.commitID=${COMMIT_SHA1}'\
|
||||
-w -s"
|
||||
fi
|
||||
done
|
||||
|
||||
export GOOS='linux'
|
||||
export GOARCH='arm'
|
||||
export GOARM='7'
|
||||
export TARGET=${TARGET_DIR}/${DIST_PREFIX}_${GOOS}_${GOARCH}v7
|
||||
echo "build => ${TARGET}"
|
||||
if [ "${DEBUG_MODE}" == "debug" ]; then
|
||||
go build -trimpath -gcflags "all=-N -l" -o ${TARGET} \
|
||||
-ldflags "-X 'github.com/xgadget-lab/nexttrace/printer.version=${BUILD_VERSION}' \
|
||||
-X 'github.com/xgadget-lab/nexttrace/printer.buildDate=${BUILD_DATE}' \
|
||||
-X 'github.com/xgadget-lab/nexttrace/printer.commitID=${COMMIT_SHA1}'\
|
||||
-w -s"
|
||||
else
|
||||
go build -trimpath -o ${TARGET} \
|
||||
-ldflags "-X 'github.com/xgadget-lab/nexttrace/printer.version=${BUILD_VERSION}' \
|
||||
-X 'github.com/xgadget-lab/nexttrace/printer.buildDate=${BUILD_DATE}' \
|
||||
-X 'github.com/xgadget-lab/nexttrace/printer.commitID=${COMMIT_SHA1}'\
|
||||
-w -s"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
40
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
40
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
---
|
||||
name: nexttrace 程序问题
|
||||
about: "提交一个 nexttrace 的程序问题报告。"
|
||||
copyright: [v2fly](https://github.com/v2fly)
|
||||
---
|
||||
|
||||
<!--
|
||||
除非特殊情况,请完整填写所有问题。不按模板发的 issue 将直接被关闭。
|
||||
如果你遇到的问题不是 nexttrace 的 bug,比如你不清楚如何配置,请在 https://github.com/xgadget-lab/nexttrace/discussions 进行讨论。
|
||||
-->
|
||||
|
||||
## 你正在使用哪个版本的 nexttrace?
|
||||
|
||||
<!-- 比如linux_amd64 macOS_arm64 -->
|
||||
|
||||
|
||||
## 你看到的异常现象是什么?
|
||||
|
||||
<!-- 请描述具体现象 -->
|
||||
|
||||
|
||||
## 你期待看到的正常表现是怎样的?
|
||||
|
||||
|
||||
|
||||
## 请附上你的命令
|
||||
|
||||
<!-- 提交 issue 前,请隐去您的隐私信息 -->
|
||||
|
||||
|
||||
## 请附上出错时软件输出的错误信息
|
||||
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
36
.github/workflows/build.yml
vendored
36
.github/workflows/build.yml
vendored
@@ -1,17 +1,31 @@
|
||||
on:
|
||||
push: # 每次带有 tag 的 push 候触发
|
||||
tags:
|
||||
- 'v*'
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
name: Build Release
|
||||
name: Test & Build Release
|
||||
jobs:
|
||||
release:
|
||||
Test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master # checkout 代码
|
||||
- uses: actions/setup-go@v2 # 配置 Go 环境
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: "1.18" # 改成自己的版本
|
||||
go-version: "1.18"
|
||||
|
||||
- name: Test
|
||||
run: go test -v -coverprofile='coverage.out' -covermode=count ./...
|
||||
|
||||
Build:
|
||||
needs: test
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: "1.18"
|
||||
|
||||
- run: bash .cross_compile.sh
|
||||
|
||||
@@ -22,8 +36,14 @@ jobs:
|
||||
files: |
|
||||
dist/nexttrace_darwin_amd64
|
||||
dist/nexttrace_darwin_arm64
|
||||
dist/nexttrace_linux_386
|
||||
dist/nexttrace_linux_amd64
|
||||
dist/nexttrace_linux_arm64
|
||||
dist/nexttrace_linux_armv7
|
||||
dist/nexttrace_linux_mips
|
||||
dist/nexttrace_openbsd_amd64
|
||||
dist/nexttrace_openbsd_arm64
|
||||
dist/nexttrace_freebsd_amd64
|
||||
dist/nexttrace_freebsd_arm64
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GT_Token }}
|
||||
|
||||
151
README.md
151
README.md
@@ -1,32 +1,53 @@
|
||||
<div align="center">
|
||||
|
||||
<img src="asset/logo.png" height="200px"/>
|
||||
<img src="asset/logo.png" height="200px" alt="NextTrace Logo"/>
|
||||
|
||||
</div>
|
||||
|
||||
# NextTrace
|
||||
|
||||
一款开源的可视化路由跟踪工具,使用Golang开发。
|
||||
一款开源的可视化路由跟踪工具,使用 Golang 开发。
|
||||
|
||||
NextTrace 只是一个实验性项目,不推荐用于生产环境下。对于路由跟踪工具,我们依旧更加推荐 WorstTrace & Besttrace。
|
||||
|
||||
## How To Use
|
||||
|
||||
### Install
|
||||
### Automated Install
|
||||
|
||||
```bash
|
||||
bash -c "$(curl -Ls https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/nt_install.sh)"
|
||||
# Note: This Script Only Supports Linux/macOS, Other Unix-Like Systems are UNAVAILABLE
|
||||
curl -Ls https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/nt_install.sh -O && sudo bash nt_install.sh
|
||||
```
|
||||
|
||||
```bash
|
||||
# GHPROXY镜像(在连接raw.githubusercontent.com网络不畅时使用)
|
||||
curl -Ls https://ghproxy.com/https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/nt_install.sh -O && sudo bash nt_install.sh
|
||||
```
|
||||
|
||||
- `Release`里面为很多系统以及不同架构提供了编译好的二进制可执行文件,如果没有可以自行编译。
|
||||
- 一些本项目的必要依赖在`Windows`上`Golang`底层实现不完全,所以目前`NextTrace`在`Windows`平台不可用。
|
||||
|
||||
### Fast Test
|
||||
|
||||
此脚本旨在快速测试服务器的到中国内地的线路,建议新手或者没有自定义`NextTrace`功能需求的用户使用。
|
||||
|
||||
```bash
|
||||
curl -Ls https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/quicklytest.sh -O && sudo bash quicklytest.sh
|
||||
```
|
||||
|
||||
```bash
|
||||
# GHPROXY镜像(在连接raw.githubusercontent.com网络不畅时使用)
|
||||
curl -Ls https://ghproxy.com/https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/quicklytest.sh -O && sudo bash quicklytest.sh
|
||||
```
|
||||
|
||||
### Get Started
|
||||
|
||||
`NextTrace`默认使用`icmp`协议发起`TraceRoute`请求,该协议同时支持`IPv4`和`IPv6`
|
||||
`NextTrace`默认使用`ICMP`协议发起`TraceRoute`请求,该协议同时支持`IPv4`和`IPv6`
|
||||
|
||||
```bash
|
||||
# IPv4 ICMP Trace
|
||||
nexttrace 1.0.0.1
|
||||
|
||||
# 获得 route-path
|
||||
nexttrace -report 1.0.0.1
|
||||
|
||||
# 表格打印(一次性输出全部跳数,需等待20-40秒)
|
||||
nexttrace -table 1.0.0.1
|
||||
|
||||
@@ -35,6 +56,7 @@ nexttrace 2606:4700:4700::1111
|
||||
```
|
||||
|
||||
`NextTrace`也可以使用`TCP`和`UDP`协议发起`Traceroute`请求,不过目前只支持`IPv4`
|
||||
|
||||
```bash
|
||||
# TCP SYN Trace
|
||||
nexttrace -T www.bing.com
|
||||
@@ -48,24 +70,68 @@ nexttrace -U 1.0.0.1
|
||||
nexttrace -U -p 53 1.0.0.1
|
||||
```
|
||||
|
||||
### IP数据库
|
||||
`NextTrace`也同样支持一些进阶功能,如 IP 反向解析、并发数控制、模式切换等
|
||||
|
||||
目前使用的IP数据库默认为我们自己搭建的API服务,如果后期遇到滥用,我们可能会选择关闭。
|
||||
```bash
|
||||
# 每一跳发送2个探测包
|
||||
nexttrace -q 2 www.hkix.net
|
||||
|
||||
我们也会在后期开放服务端源代码,您也可以根据该项目的源码自行搭建属于您的API服务器。
|
||||
# 无并发,每次只发送一个探测包
|
||||
nexttrace -r 1 www.hkix.net
|
||||
|
||||
NextTrace所有的的IP地理位置`API DEMO`可以参考[这里](https://github.com/xgadget-lab/nexttrace/blob/main/ipgeo/)
|
||||
# 打开IP反向解析功能,在IPv6的骨干网定位辅助有较大帮助
|
||||
nexttrace -rdns www.bbix.net
|
||||
|
||||
### 全部用法详见Usage菜单
|
||||
# 特色功能:打印Route-Path图
|
||||
# Route-Path图示例:
|
||||
# AS6453 塔塔通信「Singapore『Singapore』」
|
||||
# ╭╯
|
||||
# ╰AS9299 Philippine Long Distance Telephone Co.「Philippines『Metro Manila』」
|
||||
# ╭╯
|
||||
# ╰AS36776 Five9 Inc.「Philippines『Metro Manila』」
|
||||
# ╭╯
|
||||
# ╰AS37963 阿里云「ALIDNS.COM『ALIDNS.COM』」
|
||||
nexttrace -report www.time.com.my
|
||||
```
|
||||
|
||||
`NextTrace`支持用户自主选择 IP 数据库(目前支持:`LeoMoeAPI`, `IP.SB`, `IPInfo`, `IPInsight`, `IPAPI.com`)
|
||||
|
||||
```bash
|
||||
# 可以自行指定IP数据库[此处为IP.SB],不指定则默认为LeoMoeAPI
|
||||
nexttrace -d IP.SB
|
||||
## 特别的:其中 ipinfo API 需要从ipinfo自行购买服务,如有需要可以clone本项目添加其提供的token自行编译
|
||||
## TOKEN填写路径:ipgeo/tokens.go
|
||||
## 另外:由于IP.SB被滥用比较严重,会经常出现无法查询的问题,请知悉。
|
||||
## IPAPI.com限制调用较为严格,如有查询不到的情况,请几分钟后再试。
|
||||
```
|
||||
|
||||
`NextTrace`支持参数混合使用
|
||||
|
||||
```bash
|
||||
Example:
|
||||
nexttrace -d IPInsight -m 20 -p 443 -q 5 -r 20 -rdns 1.1.1.1
|
||||
nexttrace -T -q 2 -r 1 -rdns -table -report 2001:4860:4860::8888
|
||||
```
|
||||
|
||||
### IP 数据库
|
||||
|
||||
目前使用的 IP 数据库默认为我们自己搭建的 API 服务,如果后期遇到滥用,我们可能会选择关闭。
|
||||
|
||||
我们也会在后期开放服务端源代码,您也可以根据该项目的源码自行搭建属于您的 API 服务器。
|
||||
|
||||
NextTrace 所有的的 IP 地理位置`API DEMO`可以参考[这里](https://github.com/xgadget-lab/nexttrace/blob/main/ipgeo/)
|
||||
|
||||
### 全部用法详见 Usage 菜单
|
||||
|
||||
```shell
|
||||
Usage of nexttrace:
|
||||
'nexttrace [options] <hostname>' or 'nexttrace <hostname> [option...]'
|
||||
Options:
|
||||
-T Use TCP SYN for tracerouting (default port is 80)
|
||||
-U Use UDP Package for tracerouting (default port is 53 in UDP)
|
||||
-V Check Version
|
||||
-d string
|
||||
Choose IP Geograph Data Provider [LeoMoeAPI, IP.SB, IPInfo, IPInsight] (default "LeoMoeAPI")
|
||||
-displayMode string
|
||||
Choose The Display Mode [table, classic] (default "table")
|
||||
Choose IP Geograph Data Provider [LeoMoeAPI, IP.SB, IPInfo, IPInsight, IPAPI.com] (default "LeoMoeAPI")
|
||||
-m int
|
||||
Set the max number of hops (max TTL to be reached). (default 30)
|
||||
-p int
|
||||
@@ -76,51 +142,72 @@ Usage of nexttrace:
|
||||
Set ParallelRequests number. It should be 1 when there is a multi-routing. (default 18)
|
||||
-rdns
|
||||
Set whether rDNS will be display
|
||||
-table
|
||||
Output trace results as table
|
||||
-report
|
||||
Route Path
|
||||
|
||||
```
|
||||
|
||||
## 项目截图
|
||||
|
||||

|
||||
<img src=asset/screenshot.png alt="NextTrace Screenshot" width="683" height="688" />
|
||||
|
||||

|
||||
## FAQ 常见问题
|
||||
|
||||

|
||||
如果你在安装或者使用的时候遇到了问题,我们建议你不要把新建一个 `issue` 作为首选项
|
||||
|
||||
以下是我们推荐的排错流程:
|
||||
|
||||
1. 查看是否为常见问题 -> [前往 Github Wiki](https://github.com/xgadget-lab/nexttrace/wiki/FAQ---%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98%E8%A7%A3%E7%AD%94)
|
||||
2. 不会软件的参数使用 -> [前往 Github Discussions](https://github.com/xgadget-lab/nexttrace/discussions)
|
||||
3. 疑似 BUG、或者功能建议 -> [前往 Github Issues](https://github.com/xgadget-lab/nexttrace/issues)
|
||||
|
||||
## Thanks
|
||||
|
||||
[Vincent Young](https://github.com/missuo) (i@yyt.moe)
|
||||
|
||||
[Sam Sam](https://github.com/samleong123) (samsam123@samsam123.name.my)
|
||||
|
||||
[Vincent Young](https://github.com/missuo) (i@yyt.moe)
|
||||
[tsosunchia](https://github.com/tsosunchia)
|
||||
|
||||
[waiting4new](https://github.com/waiting4new)
|
||||
|
||||
FFEE_CO
|
||||
|
||||
nsnnns
|
||||
[FFEE_CO](https://github.com/fkx4-p)
|
||||
|
||||
## IP Database Copyright
|
||||
|
||||
### IPv4 Database
|
||||
|
||||
#### China MainLand
|
||||
#### China
|
||||
|
||||
* 项目组自行维护 ~ 御三家骨干网数据 ~ 5%
|
||||
|
||||
* 埃文科技 Paid Database ~ 95%
|
||||
| ISP | 类型 | 数据源 | 占比 |
|
||||
| :------------: | :----: | :-------: | :--: |
|
||||
| 电信/联通/移动 | 骨干网 | NextTrace | 10% |
|
||||
| 电信/联通/移动 | 城域网 | 埃文科技 | 90% |
|
||||
|
||||
#### WorldWide
|
||||
|
||||
* 埃文科技 Paid Database ~ 15%
|
||||
| ISP | 类型 | 数据源 | 占比 |
|
||||
| :-----: | :----: | :-------: | :--: |
|
||||
| Tier-01 | 骨干网 | IPInfo | 2% |
|
||||
| Tier-01 | 骨干网 | 埃文科技 | 3% |
|
||||
| Tier-01 | 骨干网 | IPInSight | 5% |
|
||||
| Tier-01 | 城域网 | IPInSight | 90% |
|
||||
|
||||
* IpInfo Free ~ 15%
|
||||
|
||||
* IPInSight Free ~ 70%
|
||||
| ISP | 类型 | 数据源 | 占比 |
|
||||
| :----: | :----: | :-------: | :--: |
|
||||
| Others | 骨干网 | IPInSight | 5% |
|
||||
| Others | 城域网 | IPInSight | 95% |
|
||||
|
||||
### IPv6 Database
|
||||
|
||||
| ISP | 类型 | 数据源 | 占比 |
|
||||
| :-: | :--: | :--------------: | :--: |
|
||||
| All | 全部 | IP2Location Lite | 100% |
|
||||
|
||||
This product includes IP2Location LITE data available from <a href="https://lite.ip2location.com">https://lite.ip2location.com</a>.
|
||||
|
||||
### Others
|
||||
|
||||
其他第三方API尽管集成在本项目内,但是具体的TOS以及AUP,请详见第三方API官网。如遇到IP数据错误,也请直接联系他们纠错。
|
||||
其他第三方 API 尽管集成在本项目内,但是具体的 TOS 以及 AUP,请详见第三方 API 官网。如遇到 IP 数据错误,也请直接联系他们纠错。
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 866 KiB After Width: | Height: | Size: 907 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 139 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 136 KiB |
BIN
asset/screenshot_2.png
Normal file
BIN
asset/screenshot_2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 27 KiB |
BIN
asset/screenshot_special.png
Normal file
BIN
asset/screenshot_special.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 174 KiB |
31
config/config.go
Normal file
31
config/config.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package config
|
||||
|
||||
import "os"
|
||||
|
||||
type tracerConfig struct {
|
||||
Token `yaml:"Token"`
|
||||
Preference `yaml:"Preference"`
|
||||
}
|
||||
|
||||
type Token struct {
|
||||
LeoMoeAPI string `yaml:"LeoMoeAPI"`
|
||||
IPInfo string `yaml:"IPInfo"`
|
||||
}
|
||||
|
||||
type Preference struct {
|
||||
AlwaysRoutePath bool `yaml:"AlwaysRoutePath"`
|
||||
}
|
||||
|
||||
type configPath func() (string, error)
|
||||
|
||||
func configFromRunDir() (string, error) {
|
||||
return "./", nil
|
||||
}
|
||||
|
||||
func configFromUserHomeDir() (string, error) {
|
||||
dir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return dir + "/.nexttrace/", nil
|
||||
}
|
||||
18
config/config_test.go
Normal file
18
config/config_test.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"log"
|
||||
)
|
||||
|
||||
func TestReadConfig(t *testing.T) {
|
||||
if res, err := Read(); err != nil {
|
||||
log.Println(err)
|
||||
} else {
|
||||
log.Println(res)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateConfig(t *testing.T) {
|
||||
Generate()
|
||||
}
|
||||
94
config/generate_config.go
Normal file
94
config/generate_config.go
Normal file
@@ -0,0 +1,94 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"io/ioutil"
|
||||
"fmt"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
func pathExists(path string) (bool, error) {
|
||||
_, err := os.Stat(path)
|
||||
if err == nil {
|
||||
return true, nil
|
||||
}
|
||||
if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
|
||||
func writeFile(content []byte) error {
|
||||
var err error
|
||||
var path string
|
||||
path, err = configFromUserHomeDir()
|
||||
if err != nil {
|
||||
path, err = configFromRunDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if exist, _ := pathExists(path); !exist {
|
||||
err := os.Mkdir(path, os.ModePerm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err = ioutil.WriteFile(path + "ntraceConfig.yml", []byte(content), 0644); err != nil{
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Generate() (*tracerConfig, error) {
|
||||
var leotoken string
|
||||
var iPInfoToken string
|
||||
var routePathEnable string
|
||||
|
||||
fmt.Println("这是一个配置向导,我们会帮助您生成配置文件,它是一次性的,除非您主动要求重新生成,否则它将不会再出现")
|
||||
|
||||
fmt.Println("请输入您的LeoMoeAPI Token,如果您没有,请到 Telegram Bot @NextTraceBot 获取一个")
|
||||
fmt.Scanln(&leotoken)
|
||||
if leotoken == "" {
|
||||
fmt.Println("检测到您的输入为空,您将使用公共Token。这意味着您将和所有使用此Token的客户端共用每分钟150次IP查询的额度")
|
||||
leotoken = "NextTraceDemo"
|
||||
}
|
||||
|
||||
fmt.Println("请输入您的IPInfo Token,如果您不需要使用IPInfo,可以直接回车")
|
||||
fmt.Scanln(&iPInfoToken)
|
||||
|
||||
token := Token{
|
||||
LeoMoeAPI: leotoken,
|
||||
IPInfo: iPInfoToken,
|
||||
}
|
||||
|
||||
var preference Preference
|
||||
fmt.Print("您是否希望在每次Traceroute结束后显示Route-Path图? (y/n)")
|
||||
fmt.Scanln(&routePathEnable)
|
||||
if routePathEnable == "n" || routePathEnable == "N" || routePathEnable == "no" || routePathEnable == "No" || routePathEnable == "NO" {
|
||||
preference = Preference{AlwaysRoutePath: false}
|
||||
} else {
|
||||
preference = Preference{AlwaysRoutePath: true}
|
||||
}
|
||||
|
||||
finalConfig := tracerConfig{
|
||||
Token: token,
|
||||
Preference: preference,
|
||||
}
|
||||
|
||||
yamlData, err := yaml.Marshal(&finalConfig)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = writeFile(yamlData); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
fmt.Println("配置文件创建成功")
|
||||
return &finalConfig, nil
|
||||
}
|
||||
}
|
||||
47
config/read_config.go
Normal file
47
config/read_config.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
func (c *tracerConfig) Parse(data []byte) error {
|
||||
return yaml.Unmarshal(data, c)
|
||||
}
|
||||
|
||||
func readFile(cp configPath) ([]byte, error) {
|
||||
var content []byte
|
||||
path, err := cp()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
content, err = ioutil.ReadFile(path + "ntraceConfig.yml")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return content, nil
|
||||
}
|
||||
|
||||
func Read() (*tracerConfig, error) {
|
||||
var data []byte
|
||||
var err error
|
||||
|
||||
data, err = readFile(configFromRunDir)
|
||||
|
||||
if err != nil {
|
||||
data, err = readFile(configFromUserHomeDir)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var config tracerConfig
|
||||
if err := config.Parse(data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &config, err
|
||||
}
|
||||
2
go.mod
2
go.mod
@@ -11,7 +11,7 @@ require (
|
||||
require (
|
||||
github.com/mattn/go-colorable v0.1.9 // indirect
|
||||
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||
github.com/panjf2000/ants/v2 v2.5.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
|
||||
require (
|
||||
|
||||
6
go.sum
6
go.sum
@@ -1,4 +1,3 @@
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@@ -13,8 +12,6 @@ github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9
|
||||
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/panjf2000/ants/v2 v2.5.0 h1:1rWGWSnxCsQBga+nQbA4/iY6VMeNoOIAM0ZWh9u3q2Q=
|
||||
github.com/panjf2000/ants/v2 v2.5.0/go.mod h1:cU93usDlihJZ5CfRGNDYsiBYvoilLvBF5Qp/BT2GNRE=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rodaine/table v1.0.1 h1:U/VwCnUxlVYxw8+NJiLIuCxA/xa6jL38MY3FYysVWWQ=
|
||||
@@ -52,7 +49,8 @@ golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapK
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
43
ipgeo/ipapicom.go
Normal file
43
ipgeo/ipapicom.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package ipgeo
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func IPApiCom(ip string) (*IPGeoData, error) {
|
||||
url := "http://ip-api.com/json/" + ip + "?fields=status,message,country,regionName,city,isp,as"
|
||||
client := &http.Client{
|
||||
// 2 秒超时
|
||||
Timeout: 2 * time.Second,
|
||||
}
|
||||
req, _ := http.NewRequest("GET", url, nil)
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0")
|
||||
content, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Println("ip-api.com 请求超时(2s),请切换其他API使用")
|
||||
return nil, err
|
||||
}
|
||||
body, _ := ioutil.ReadAll(content.Body)
|
||||
res := gjson.ParseBytes(body)
|
||||
|
||||
if res.Get("status").String() != "success" {
|
||||
return &IPGeoData{}, errors.New("超过API阈值")
|
||||
}
|
||||
|
||||
re := regexp.MustCompile("[0-9]+")
|
||||
|
||||
return &IPGeoData{
|
||||
Asnumber: re.FindString(res.Get("as").String()),
|
||||
Country: res.Get("country").String(),
|
||||
City: res.Get("city").String(),
|
||||
Prov: res.Get("regionName").String(),
|
||||
Isp: res.Get("isp").String(),
|
||||
}, nil
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package ipgeo
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type IPGeoData struct {
|
||||
Asnumber string
|
||||
@@ -22,7 +24,11 @@ func GetSource(s string) Source {
|
||||
return IPSB
|
||||
case "IPINSIGHT":
|
||||
return IPInSight
|
||||
case "IPAPI.COM":
|
||||
return IPApiCom
|
||||
case "IPINFO":
|
||||
return IPInfo
|
||||
default:
|
||||
return nil
|
||||
return LeoIP
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,12 @@ func TestLeoIP(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIPSB(t *testing.T) {
|
||||
res, err := IPSB("1.1.1.1")
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, res)
|
||||
assert.NotEmpty(t, res.Asnumber)
|
||||
assert.NotEmpty(t, res.Isp)
|
||||
// Not available
|
||||
//res, err := IPSB("1.1.1.1")
|
||||
//assert.Nil(t, err)
|
||||
//assert.NotNil(t, res)
|
||||
//assert.NotEmpty(t, res.Asnumber)
|
||||
//assert.NotEmpty(t, res.Isp)
|
||||
}
|
||||
|
||||
func TestIPInfo(t *testing.T) {
|
||||
@@ -40,3 +41,12 @@ func TestIPInSight(t *testing.T) {
|
||||
// 这个库有时候不提供城市信息,返回值为""
|
||||
//assert.NotEmpty(t, res.City)
|
||||
}
|
||||
|
||||
func TestIPApiCom(t *testing.T) {
|
||||
res, err := IPApiCom("1.1.1.1")
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, res)
|
||||
assert.NotEmpty(t, res.Country)
|
||||
assert.NotEmpty(t, res.City)
|
||||
assert.NotEmpty(t, res.Prov)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
)
|
||||
|
||||
func IPInfo(ip string) (*IPGeoData, error) {
|
||||
|
||||
resp, err := http.Get("https://ipinfo.io/" + ip + "?token=" + token.ipinfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -2,7 +2,9 @@ package ipgeo
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
@@ -11,7 +13,7 @@ import (
|
||||
func IPSB(ip string) (*IPGeoData, error) {
|
||||
url := "https://api.ip.sb/geoip/" + ip
|
||||
client := &http.Client{
|
||||
// 2秒超时
|
||||
// 2 秒超时
|
||||
Timeout: 2 * time.Second,
|
||||
}
|
||||
req, _ := http.NewRequest("GET", url, nil)
|
||||
@@ -19,11 +21,17 @@ func IPSB(ip string) (*IPGeoData, error) {
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0")
|
||||
content, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Println("api.ip.sb 请求超时(2s),请切换其他API使用")
|
||||
return nil, err
|
||||
}
|
||||
body, _ := ioutil.ReadAll(content.Body)
|
||||
res := gjson.ParseBytes(body)
|
||||
|
||||
if res.Get("country").String() == "" {
|
||||
// 什么都拿不到,证明被Cloudflare风控了
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return &IPGeoData{
|
||||
Asnumber: res.Get("asn").String(),
|
||||
Country: res.Get("country").String(),
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package ipgeo
|
||||
|
||||
import "github.com/xgadget-lab/nexttrace/config"
|
||||
|
||||
type tokenData struct {
|
||||
ipinsight string
|
||||
ipinfo string
|
||||
@@ -11,3 +13,9 @@ var token = tokenData{
|
||||
ipinfo: "",
|
||||
ipleo: "NextTraceDemo",
|
||||
}
|
||||
|
||||
|
||||
func SetToken(c config.Token) {
|
||||
token.ipleo = c.LeoMoeAPI
|
||||
token.ipinfo = c.IPInfo
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
package listener_channel
|
||||
|
||||
import (
|
||||
"golang.org/x/net/context"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ReceivedMessage struct {
|
||||
N *int
|
||||
Peer net.Addr
|
||||
Msg []byte
|
||||
Err error
|
||||
}
|
||||
|
||||
type ListenerChannel struct {
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
Conn net.PacketConn
|
||||
Messages chan ReceivedMessage
|
||||
}
|
||||
|
||||
func New(conn net.PacketConn) *ListenerChannel {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
results := make(chan ReceivedMessage, 50)
|
||||
|
||||
return &ListenerChannel{Conn: conn, ctx: ctx, cancel: cancel, Messages: results}
|
||||
}
|
||||
|
||||
func (l *ListenerChannel) Start() {
|
||||
for {
|
||||
select {
|
||||
case <-l.ctx.Done():
|
||||
return
|
||||
default:
|
||||
}
|
||||
|
||||
reply := make([]byte, 1500)
|
||||
err := l.Conn.SetReadDeadline(time.Now().Add(2 * time.Second))
|
||||
if err != nil {
|
||||
l.Messages <- ReceivedMessage{Err: err}
|
||||
continue
|
||||
}
|
||||
|
||||
n, peer, err := l.Conn.ReadFrom(reply)
|
||||
if err != nil {
|
||||
l.Messages <- ReceivedMessage{Err: err}
|
||||
continue
|
||||
}
|
||||
l.Messages <- ReceivedMessage{
|
||||
N: &n,
|
||||
Peer: peer,
|
||||
Err: nil,
|
||||
Msg: reply,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ListenerChannel) Stop() {
|
||||
l.cancel()
|
||||
}
|
||||
93
main.go
93
main.go
@@ -5,8 +5,10 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/xgadget-lab/nexttrace/config"
|
||||
"github.com/xgadget-lab/nexttrace/ipgeo"
|
||||
"github.com/xgadget-lab/nexttrace/printer"
|
||||
"github.com/xgadget-lab/nexttrace/reporter"
|
||||
@@ -14,34 +16,66 @@ import (
|
||||
"github.com/xgadget-lab/nexttrace/util"
|
||||
)
|
||||
|
||||
var tcpSYNFlag = flag.Bool("T", false, "Use TCP SYN for tracerouting (default port is 80)")
|
||||
var udpPackageFlag = flag.Bool("U", false, "Use UDP Package for tracerouting (default port is 53 in UDP)")
|
||||
var port = flag.Int("p", 80, "Set SYN Traceroute Port")
|
||||
var numMeasurements = flag.Int("q", 3, "Set the number of probes per each hop.")
|
||||
var parallelRequests = flag.Int("r", 18, "Set ParallelRequests number. It should be 1 when there is a multi-routing.")
|
||||
var maxHops = flag.Int("m", 30, "Set the max number of hops (max TTL to be reached).")
|
||||
var dataOrigin = flag.String("d", "LeoMoeAPI", "Choose IP Geograph Data Provider [LeoMoeAPI, IP.SB, IPInfo, IPInsight]")
|
||||
var rdnsenable = flag.Bool("rdns", false, "Set whether rDNS will be display")
|
||||
var routePath = flag.Bool("report", false, "Route Path")
|
||||
var realtimePrint = flag.Bool("realtime", false, "Output trace results in runtime")
|
||||
var tablePrint = flag.Bool("table", false, "Output trace results as table")
|
||||
var fSet = flag.NewFlagSet("", flag.ExitOnError)
|
||||
var tcpSYNFlag = fSet.Bool("T", false, "Use TCP SYN for tracerouting (default port is 80)")
|
||||
var udpPackageFlag = fSet.Bool("U", false, "Use UDP Package for tracerouting (default port is 53 in UDP)")
|
||||
var port = fSet.Int("p", 80, "Set SYN Traceroute Port")
|
||||
var numMeasurements = fSet.Int("q", 3, "Set the number of probes per each hop.")
|
||||
var parallelRequests = fSet.Int("r", 18, "Set ParallelRequests number. It should be 1 when there is a multi-routing.")
|
||||
var maxHops = fSet.Int("m", 30, "Set the max number of hops (max TTL to be reached).")
|
||||
var dataOrigin = fSet.String("d", "LeoMoeAPI", "Choose IP Geograph Data Provider [LeoMoeAPI, IP.SB, IPInfo, IPInsight, IPAPI.com]")
|
||||
var rdnsenable = fSet.Bool("rdns", false, "Set whether rDNS will be display")
|
||||
var routePath = fSet.Bool("report", false, "Route Path")
|
||||
var tablePrint = fSet.Bool("table", false, "Output trace results as table")
|
||||
var ver = fSet.Bool("V", false, "Check Version")
|
||||
|
||||
func printArgHelp() {
|
||||
fmt.Println("\nArgs Error\nUsage : 'nexttrace [option...] HOSTNAME' or 'nexttrace HOSTNAME [option...]'\nOPTIONS: [-VTU] [-d DATAORIGIN.STR ] [ -m TTL ] [ -p PORT ] [ -q PROBES.COUNT ] [ -r PARALLELREQUESTS.COUNT ] [-rdns] [ -table ] -report")
|
||||
fSet.PrintDefaults()
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
func flagApply() string {
|
||||
flag.Parse()
|
||||
ipArg := flag.Args()
|
||||
if flag.NArg() != 1 {
|
||||
fmt.Println("Args Error\nUsage : ./nexttrace [-T] [-rdns] [-displayMode <displayMode>] [-d <dataOrigin> ] [ -m <hops> ] [ -p <port> ] [ -q <probes> ] [ -r <parallelrequests> ] <hostname>")
|
||||
os.Exit(2)
|
||||
printer.Version()
|
||||
|
||||
target := ""
|
||||
if len(os.Args) < 2 {
|
||||
printArgHelp()
|
||||
}
|
||||
return ipArg[0]
|
||||
if !strings.HasPrefix(os.Args[1], "-") {
|
||||
target = os.Args[1]
|
||||
fSet.Parse(os.Args[2:])
|
||||
} else {
|
||||
fSet.Parse(os.Args[1:])
|
||||
target = fSet.Arg(0)
|
||||
}
|
||||
if *ver {
|
||||
os.Exit(0)
|
||||
}
|
||||
if target == "" {
|
||||
printArgHelp()
|
||||
}
|
||||
return target
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
domain := flagApply()
|
||||
|
||||
if os.Getuid() != 0 {
|
||||
log.Fatalln("Traceroute requires root/sudo privileges.")
|
||||
}
|
||||
|
||||
domain := flagApply()
|
||||
configData, err := config.Read();
|
||||
|
||||
if err != nil {
|
||||
if configData, err = config.Generate(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
ipgeo.SetToken(configData.Token)
|
||||
|
||||
ip := util.DomainLookUp(domain)
|
||||
printer.PrintTraceRouteNav(ip, domain, *dataOrigin)
|
||||
|
||||
@@ -81,21 +115,16 @@ func main() {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
if *routePath {
|
||||
if (*tcpSYNFlag && *udpPackageFlag) || *tablePrint {
|
||||
printer.TracerouteTablePrinter(res)
|
||||
} else if *tcpSYNFlag || *udpPackageFlag {
|
||||
printer.TraceroutePrinter(res)
|
||||
}
|
||||
|
||||
p := configData.Preference
|
||||
|
||||
if *routePath || p.AlwaysRoutePath {
|
||||
r := reporter.New(res, ip.String())
|
||||
r.Print()
|
||||
return
|
||||
}
|
||||
|
||||
if m == trace.ICMPTrace && *tablePrint {
|
||||
printer.TracerouteTablePrinter(res)
|
||||
}
|
||||
|
||||
if m == trace.TCPTrace || m == trace.UDPTrace {
|
||||
if *realtimePrint {
|
||||
printer.TraceroutePrinter(res)
|
||||
} else {
|
||||
printer.TracerouteTablePrinter(res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
461
nt_install.sh
461
nt_install.sh
@@ -1,266 +1,297 @@
|
||||
#!/bin/bash
|
||||
|
||||
auto=False
|
||||
#是否忽略一切警告,按默认执行
|
||||
if [[ $1 == "--auto" ]]; then
|
||||
auto=True
|
||||
echo "自动运行中"
|
||||
fi
|
||||
|
||||
usrPath="/usr/local/bin"
|
||||
|
||||
function red() {
|
||||
echo -e "\033[31m""${1}""\033[0m"
|
||||
}
|
||||
|
||||
checkRootPermit() {
|
||||
[[ $EUID -ne 0 ]] && echo "请使用sudo/root权限运行本脚本" && exit 1
|
||||
[[ $EUID -ne 0 ]] && red "请使用sudo/root权限运行本脚本" && exit 1
|
||||
}
|
||||
|
||||
checkSystemArch() {
|
||||
arch=$(uname -m)
|
||||
if [[ $arch == "x86_64" ]]; then
|
||||
archParam="amd64"
|
||||
fi
|
||||
|
||||
if [[ $arch == "aarch64" ]]; then
|
||||
archParam="arm64"
|
||||
fi
|
||||
|
||||
if [[ $arch == "arm64" ]]; then
|
||||
archParam="arm64"
|
||||
fi
|
||||
|
||||
if [[ $archParam == "" ]]; then
|
||||
echo "未知的系统架构,请联系作者"
|
||||
exit 1
|
||||
fi
|
||||
arch=$(uname -m)
|
||||
case $arch in
|
||||
'x86_64')
|
||||
archParam='amd64'
|
||||
;;
|
||||
'mips')
|
||||
archParam='mips'
|
||||
;;
|
||||
'arm64' | 'aarch64')
|
||||
archParam="arm64"
|
||||
;;
|
||||
'armv7l')
|
||||
archParam='armv7'
|
||||
;;
|
||||
'i386')
|
||||
archParam="386"
|
||||
;;
|
||||
*)
|
||||
red "未知的系统架构,请联系开发者."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
checkSystemDistribution() {
|
||||
case "$OSTYPE" in
|
||||
darwin*)
|
||||
osDistribution="darwin"
|
||||
downPath="/var/tmp/nexttrace"
|
||||
;;
|
||||
linux*)
|
||||
osDistribution="linux"
|
||||
downPath="/var/tmp/nexttrace"
|
||||
;;
|
||||
*)
|
||||
echo "unknown: $OSTYPE"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
case "$OSTYPE" in
|
||||
darwin*)
|
||||
osDistribution="darwin"
|
||||
downPath="/var/tmp/nexttrace"
|
||||
;;
|
||||
linux*)
|
||||
osDistribution="linux"
|
||||
downPath="/var/tmp/nexttrace"
|
||||
;;
|
||||
*)
|
||||
red "安装脚本暂不支持的操作系统: $OSTYPE"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
getLocation() {
|
||||
echo "正在获取地理位置信息..."
|
||||
countryCode=$(curl -s "http://ip-api.com/line/?fields=countryCode")
|
||||
red "正在获取地理位置信息..."
|
||||
countryCode=$(curl -s "http://ip-api.com/line/?fields=countryCode")
|
||||
if [ "$countryCode" == "CN" ]; then
|
||||
if [[ $auto == True ]]; then
|
||||
URLprefix="https://ghproxy.com/"
|
||||
else
|
||||
read -r -p "检测到国内网络环境,是否使用镜像下载以加速(n/y)[y]" input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
URLprefix="https://ghproxy.com/"
|
||||
;;
|
||||
|
||||
[nN][oO] | [nN])
|
||||
URLprefix=""
|
||||
red "您选择了不使用镜像,下载可能会变得异常缓慢,或者失败"
|
||||
;;
|
||||
|
||||
*)
|
||||
URLprefix="https://ghproxy.com/"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
installWgetPackage() {
|
||||
# macOS should install wget originally. Nothing to do
|
||||
echo "wget 正在安装中..."
|
||||
# try apt
|
||||
apt-get -h &>/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
# 先更新一下数据源,有些机器数据源比较老可能会404
|
||||
apt-get update -y &>/dev/null
|
||||
apt-get install wget -y &>/dev/null
|
||||
fi
|
||||
|
||||
# try yum
|
||||
yum -h &>/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
yum -y update &>/dev/null
|
||||
yum install wget -y &>/dev/null
|
||||
fi
|
||||
|
||||
# try dnf
|
||||
dnf -h &>/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
dnf check-update &>/dev/null
|
||||
dnf install wget -y &>/dev/null
|
||||
fi
|
||||
|
||||
# try pacman
|
||||
pacman -h &>/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
pacman -Sy &>/dev/null
|
||||
pacman -S wget &>/dev/null
|
||||
fi
|
||||
|
||||
wget -h &>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "wget 安装失败"
|
||||
exit 1
|
||||
fi
|
||||
ask_if() {
|
||||
local choice=""
|
||||
red "${1}"
|
||||
read -r choice
|
||||
[[ $choice == y ]] && return 0 || return 1
|
||||
}
|
||||
|
||||
installJqPackage() {
|
||||
# macOS should install wget originally. Nothing to do
|
||||
echo "jq 正在安装中..."
|
||||
# try apt
|
||||
apt-get -h &>/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
# 先更新一下数据源,有些机器数据源比较老可能会404
|
||||
apt-get update -y &>/dev/null
|
||||
apt-get install jq -y &>/dev/null
|
||||
fi
|
||||
|
||||
# try yum
|
||||
yum -h &>/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
yum -y update &>/dev/null
|
||||
yum install jq -y &>/dev/null
|
||||
fi
|
||||
|
||||
# try dnf
|
||||
dnf -h &>/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
dnf check-update &>/dev/null
|
||||
dnf install jq -y &>/dev/null
|
||||
fi
|
||||
|
||||
# try pacman
|
||||
pacman -h &>/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
pacman -Sy &>/dev/null
|
||||
pacman -S jq &>/dev/null
|
||||
fi
|
||||
|
||||
jq -h &>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "jq 安装失败"
|
||||
exit 1
|
||||
fi
|
||||
#检查脚本更新
|
||||
check_script_update() {
|
||||
if [[ ${osDistribution} == "darwin" ]]; then
|
||||
[ "$(md5 <"${BASH_SOURCE[0]}")" == "$(curl -sL ${URLprefix}"https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/nt_install.sh" | md5)" ] && return 1 || return 0
|
||||
else
|
||||
[ "$(md5sum "${BASH_SOURCE[0]}" | awk '{print $1}')" == "$(md5sum <(curl -sL ${URLprefix}"https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/nt_install.sh") | awk '{print $1}')" ] && return 1 || return 0
|
||||
fi
|
||||
}
|
||||
|
||||
checkWgetPackage() {
|
||||
wget -h &>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
read -r -p "您还没有安装wget,是否安装? (y/n)" input
|
||||
#更新脚本
|
||||
update_script() {
|
||||
if curl -sL -o "${BASH_SOURCE[0]}" ${URLprefix}"https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/nt_install.sh" || curl -sL -o "${BASH_SOURCE[0]}" ${URLprefix}"https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/nt_install.sh"; then
|
||||
red "nt_install.sh更新完成,正在重启脚本..."
|
||||
exec bash "${BASH_SOURCE[0]}" --auto
|
||||
else
|
||||
red "更新nt_install.sh失败!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
installWgetPackage
|
||||
;;
|
||||
ask_update_script() {
|
||||
if check_script_update; then
|
||||
red "nt_install.sh可升级"
|
||||
[[ $auto == True ]] && update_script
|
||||
ask_if "是否升级脚本?(n/y):[n]" && update_script
|
||||
else
|
||||
red "nt_install.sh已经是最新版本"
|
||||
fi
|
||||
}
|
||||
|
||||
[nN][oO] | [nN])
|
||||
echo "您选择了取消安装,脚本即将退出"
|
||||
exit 1
|
||||
;;
|
||||
checkPackageManger() {
|
||||
if [[ ${osDistribution} == "darwin" ]]; then
|
||||
# brew update
|
||||
PACKAGE_MANAGEMENT_INSTALL='brew install'
|
||||
PACKAGE_MANAGEMENT_REMOVE='brew uninstall'
|
||||
return 0
|
||||
fi
|
||||
if [[ "$(which apt)" ]]; then
|
||||
apt-get update
|
||||
PACKAGE_MANAGEMENT_INSTALL='apt-get -y --no-install-recommends install'
|
||||
PACKAGE_MANAGEMENT_REMOVE='apt-get purge'
|
||||
elif [[ "$(which dnf)" ]]; then
|
||||
dnf check-update
|
||||
PACKAGE_MANAGEMENT_INSTALL='dnf -y install'
|
||||
PACKAGE_MANAGEMENT_REMOVE='dnf remove'
|
||||
elif [[ "$(which yum)" ]]; then
|
||||
PACKAGE_MANAGEMENT_INSTALL='yum -y install'
|
||||
PACKAGE_MANAGEMENT_REMOVE='yum remove'
|
||||
elif [[ "$(which zypper)" ]]; then
|
||||
zypper refresh
|
||||
PACKAGE_MANAGEMENT_INSTALL='zypper install -y --no-recommends'
|
||||
PACKAGE_MANAGEMENT_REMOVE='zypper remove'
|
||||
elif [[ "$(which pacman)" ]]; then
|
||||
PACKAGE_MANAGEMENT_INSTALL='pacman -Syu --noconfirm'
|
||||
PACKAGE_MANAGEMENT_REMOVE='pacman -Rsn'
|
||||
else
|
||||
red "error: The script does not support the package manager in this operating system."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
*)
|
||||
installWgetPackage
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
install_software() {
|
||||
package_name="$1"
|
||||
which "$package_name" >/dev/null 2>&1 && return
|
||||
[[ ${osDistribution} == "darwin" ]] && echo -e "由于macOS brew的权限限制,请以非root权限执行下面一行提示的命令后再次运行本脚本(注意不要在该命令加sudo!):\nbrew update && ${PACKAGE_MANAGEMENT_INSTALL} $package_name " && exit 0
|
||||
red "${package_name} 正在安装中...(此步骤时间可能较长,请耐心等待)"
|
||||
if ${PACKAGE_MANAGEMENT_INSTALL} "$package_name"; then
|
||||
red "info: $package_name is installed."
|
||||
else
|
||||
red "error: Installation of $package_name failed, please check your network."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
checkVersion() {
|
||||
echo "正在检查版本..."
|
||||
version=$(curl -sL https://api.github.com/repos/xgadget-lab/nexttrace/releases/latest | jq -r '.tag_name')
|
||||
if [[ $version == "" ]]; then
|
||||
echo "获取版本失败,请检查网络连接"
|
||||
exit 1
|
||||
fi
|
||||
echo 当前最新release版本:${version}
|
||||
read -r -p "是否安装/更新软件? (y/n)" input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
break
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
echo "您选择了取消安装/更新,脚本即将退出"
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
checkJqPackage() {
|
||||
jq -h &>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "您还没有安装jq, 当您取消安装,我们会使用awk获取当前版本号。"
|
||||
read -r -p "但是如遇Github变更API,这可能会存在问题,是否安装? (y/n)" input
|
||||
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
installJqPackage
|
||||
;;
|
||||
|
||||
[nN][oO] | [nN])
|
||||
echo "您选择了取消安装"
|
||||
return 0
|
||||
;;
|
||||
|
||||
*)
|
||||
installJqPackage
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
return 1
|
||||
which nexttrace >/dev/null 2>&1 || return
|
||||
red "正在检查版本..."
|
||||
version=$(curl -sL https://api.github.com/repos/xgadget-lab/nexttrace/releases/latest | jq -r '.tag_name')
|
||||
if [[ $version == "" ]]; then
|
||||
red "获取版本失败,请检查网络连接"
|
||||
exit 1
|
||||
fi
|
||||
currentVersion=$(nexttrace -V | head -n 1 | awk '{print $2}')
|
||||
if [[ $currentVersion == "$version" ]]; then
|
||||
red "当前版本已是最新版本"
|
||||
exit 0
|
||||
fi
|
||||
red "当前最新release版本:${version}"
|
||||
red "您当前的版本:${currentVersion}"
|
||||
if [[ $auto == True ]]; then
|
||||
return 0
|
||||
fi
|
||||
read -r -p "是否更新软件? (n/y):[n]" input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
return 0
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
red "您选择了取消更新,脚本即将退出"
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
red "您选择了取消更新,脚本即将退出"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
downloadBinrayFile() {
|
||||
echo "正在获取最新版的 NextTrace 发行版文件信息..."
|
||||
checkJqPackage
|
||||
# 简单说明一下,Github提供了一个API,可以获取最新发行版本的二进制文件下载地址(对应的是browser_download_url),根据刚刚测得的osDistribution、archParam,获取对应的下载地址
|
||||
if [[ $? -eq 1 ]]; then
|
||||
# 支持 jq 不回退
|
||||
# echo nexttrace_${osDistribution}_${archParam}
|
||||
latestURL=$(curl -s https://api.github.com/repos/xgadget-lab/nexttrace/releases/latest | jq ".assets[] | select(.name == \"nexttrace_${osDistribution}_${archParam}\") | .browser_download_url")
|
||||
latestURL=${latestURL:1:-1}
|
||||
else
|
||||
# 不支持 jq,用户拒绝安装,回退 awk
|
||||
latestURL=$(curl -s https://api.github.com/repos/xgadget-lab/nexttrace/releases/latest | grep -i "browser_download_url.*${osDistribution}.*${archParam}" | awk -F '"' '{print $4}')
|
||||
fi
|
||||
if [ "$countryCode" == "CN" ]; then
|
||||
read -r -p "检测到国内网络环境,是否使用镜像下载以加速(y/n)" input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
latestURL="https://ghproxy.com/"$latestURL
|
||||
;;
|
||||
red "正在获取最新版的 NextTrace 发行版文件信息..."
|
||||
# 简单说明一下,Github提供了一个API,可以获取最新发行版本的二进制文件下载地址(对应的是browser_download_url),根据刚刚测得的osDistribution、archParam,获取对应的下载地址
|
||||
# red nexttrace_${osDistribution}_${archParam}
|
||||
latestURL=$(curl -s https://api.github.com/repos/xgadget-lab/nexttrace/releases/latest | jq ".assets[] | select(.name == \"nexttrace_${osDistribution}_${archParam}\") | .browser_download_url")
|
||||
latestURL=${latestURL:1:$((${#latestURL} - 1 - 1))}
|
||||
# if [ "$countryCode" == "CN" ]; then
|
||||
# if [[ $auto == True ]]; then
|
||||
# latestURL="https://ghproxy.com/"$latestURL
|
||||
# else
|
||||
# read -r -p "检测到国内网络环境,是否使用镜像下载以加速(n/y)[y]" input
|
||||
# case $input in
|
||||
# [yY][eE][sS] | [yY])
|
||||
# latestURL="https://ghproxy.com/"$latestURL
|
||||
# ;;
|
||||
|
||||
[nN][oO] | [nN])
|
||||
echo "您选择了不使用镜像,下载可能会变得异常缓慢,或者失败"
|
||||
;;
|
||||
# [nN][oO] | [nN])
|
||||
# red "您选择了不使用镜像,下载可能会变得异常缓慢,或者失败"
|
||||
# ;;
|
||||
|
||||
*)
|
||||
latestURL="https://ghproxy.com/"$latestURL
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
# *)
|
||||
# latestURL="https://ghproxy.com/"$latestURL
|
||||
# ;;
|
||||
# esac
|
||||
# fi
|
||||
# fi
|
||||
latestURL=$URLprefix$latestURL
|
||||
|
||||
echo "正在下载 NextTrace 二进制文件..."
|
||||
wget -O ${downPath} ${latestURL} &>/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "NextTrace 现在已经在您的系统中可用"
|
||||
changeMode
|
||||
mv ${downPath} ${usrPath}
|
||||
if [[ ${osDistribution} == "macOS" ]]; then
|
||||
xattr -r -d com.apple.quarantine ${usrPath}/nexttrace
|
||||
fi
|
||||
else
|
||||
echo "NextTrace 下载失败,请检查您的网络是否正常"
|
||||
exit 1
|
||||
fi
|
||||
red "正在下载 NextTrace 二进制文件..."
|
||||
if wget -O ${downPath} "${latestURL}"; then
|
||||
red "NextTrace 现在已经在您的系统中可用"
|
||||
changeMode
|
||||
mv ${downPath} ${usrPath}
|
||||
else
|
||||
red "NextTrace 下载失败,请检查您的网络是否正常"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
changeMode() {
|
||||
chmod +x ${downPath} &>/dev/null
|
||||
chmod +x ${downPath}
|
||||
[[ ${osDistribution} == "darwin" ]] && xattr -r -d com.apple.quarantine ${downPath}
|
||||
}
|
||||
|
||||
runBinrayFileHelp() {
|
||||
if [ -e ${usrPath} ]; then
|
||||
${usrPath}/nexttrace -h
|
||||
if [ -e ${usrPath} ]; then
|
||||
${usrPath}/nexttrace -h
|
||||
fi
|
||||
red "You may need to execute a command to remove dependent software: $PACKAGE_MANAGEMENT_REMOVE wget jq"
|
||||
}
|
||||
|
||||
addCronTask() {
|
||||
read -r -p "是否添加自动更新任务?(n/y):[n]" input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
if [[ ${osDistribution} == "darwin" ]]; then
|
||||
crontab -l >crontab.bak 2>/dev/null
|
||||
sed -i '' '/nt_install.sh/d' crontab.bak
|
||||
elif [[ ${osDistribution} == "linux" ]]; then
|
||||
crontab -l >crontab.bak 2>/dev/null
|
||||
sed -i '/nt_install.sh/d' crontab.bak
|
||||
else
|
||||
red "暂不支持您的系统,无法自动添加crontab任务"
|
||||
return
|
||||
fi
|
||||
echo "1 1 * * * $(dirname "$(readlink -f "$0")")/nt_install.sh --auto >> /var/log/nt_install.log" >>crontab.bak
|
||||
crontab crontab.bak
|
||||
rm -f crontab.bak
|
||||
;;
|
||||
[nN][oO] | [nN])
|
||||
red "您选择了不添加自动更新任务,您也可以通过命令 再次执行此脚本 手动更新"
|
||||
;;
|
||||
*)
|
||||
red "您选择了不添加自动更新任务,您可以通过命令 再次执行此脚本 手动更新"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Check Procedure
|
||||
checkRootPermit
|
||||
checkSystemDistribution
|
||||
checkSystemArch
|
||||
checkWgetPackage
|
||||
# TODO: 检查版本并更新
|
||||
#checkVersion
|
||||
getLocation
|
||||
ask_update_script
|
||||
checkPackageManger
|
||||
install_software wget
|
||||
install_software jq
|
||||
checkVersion
|
||||
|
||||
# Download Procedure
|
||||
getLocation
|
||||
downloadBinrayFile
|
||||
|
||||
# Run Procedure
|
||||
runBinrayFileHelp
|
||||
[[ $auto != True ]] && addCronTask
|
||||
|
||||
@@ -5,6 +5,15 @@ import (
|
||||
"net"
|
||||
)
|
||||
|
||||
var version = "v0.0.0.alpha"
|
||||
var buildDate = ""
|
||||
var commitID = ""
|
||||
|
||||
func Version() {
|
||||
fmt.Println("NextTrace", version, buildDate, commitID)
|
||||
fmt.Println("XGadget-lab Leo (leo.moe) & Vincent (vincent.moe) & zhshch (xzhsh.ch)")
|
||||
}
|
||||
|
||||
func PrintTraceRouteNav(ip net.IP, domain string, dataOrigin string) {
|
||||
fmt.Println("IP Geo Data Provider: " + dataOrigin)
|
||||
|
||||
|
||||
@@ -52,11 +52,11 @@ func formatIpGeoData(ip string, data *ipgeo.IPGeoData) string {
|
||||
// TODO: 判断阿里云和腾讯云内网,数据不足,有待进一步完善
|
||||
// TODO: 移动IDC判断到Hop.fetchIPData函数,减少API调用
|
||||
if strings.HasPrefix(ip, "9.") {
|
||||
res = append(res, "局域网", "腾讯云")
|
||||
res = append(res, "LAN Address")
|
||||
} else if strings.HasPrefix(ip, "11.") {
|
||||
res = append(res, "局域网", "阿里云")
|
||||
res = append(res, "LAN Address")
|
||||
} else if data.Country == "" {
|
||||
res = append(res, "局域网")
|
||||
res = append(res, "LAN Address")
|
||||
} else {
|
||||
// 有些IP的归属信息为空,这个时候将ISP的信息填入
|
||||
if data.Owner == "" {
|
||||
|
||||
104
printer/printer_test.go
Normal file
104
printer/printer_test.go
Normal file
@@ -0,0 +1,104 @@
|
||||
package printer
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/xgadget-lab/nexttrace/ipgeo"
|
||||
"github.com/xgadget-lab/nexttrace/trace"
|
||||
"github.com/xgadget-lab/nexttrace/util"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestPrintTraceRouteNav(t *testing.T) {
|
||||
PrintTraceRouteNav(util.DomainLookUp("1.1.1.1"), "1.1.1.1", "dataOrigin")
|
||||
}
|
||||
|
||||
var testGeo = &ipgeo.IPGeoData{
|
||||
Asnumber: "TestAsnumber",
|
||||
Country: "TestCountry",
|
||||
Prov: "TestProv",
|
||||
City: "TestCity",
|
||||
District: "TestDistrict",
|
||||
Owner: "TestOwner",
|
||||
Isp: "TestIsp",
|
||||
}
|
||||
|
||||
var testResult = &trace.Result{
|
||||
Hops: [][]trace.Hop{
|
||||
{
|
||||
{
|
||||
Success: true,
|
||||
Address: &net.IPAddr{IP: net.ParseIP("192.168.3.1")},
|
||||
Hostname: "test",
|
||||
TTL: 0,
|
||||
RTT: 10 * time.Millisecond,
|
||||
Error: nil,
|
||||
Geo: testGeo,
|
||||
},
|
||||
{
|
||||
Success: true,
|
||||
Address: &net.IPAddr{IP: net.ParseIP("192.168.3.1")},
|
||||
Hostname: "test",
|
||||
TTL: 0,
|
||||
RTT: 10 * time.Millisecond,
|
||||
Error: nil,
|
||||
Geo: testGeo,
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
Success: false,
|
||||
Address: nil,
|
||||
Hostname: "",
|
||||
TTL: 0,
|
||||
RTT: 0,
|
||||
Error: errors.New("test error"),
|
||||
Geo: nil,
|
||||
},
|
||||
{
|
||||
Success: true,
|
||||
Address: &net.IPAddr{IP: net.ParseIP("192.168.3.1")},
|
||||
Hostname: "test",
|
||||
TTL: 0,
|
||||
RTT: 10 * time.Millisecond,
|
||||
Error: nil,
|
||||
Geo: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
Success: true,
|
||||
Address: &net.IPAddr{IP: net.ParseIP("192.168.3.1")},
|
||||
Hostname: "test",
|
||||
TTL: 0,
|
||||
RTT: 0,
|
||||
Error: nil,
|
||||
Geo: &ipgeo.IPGeoData{},
|
||||
},
|
||||
{
|
||||
Success: true,
|
||||
Address: &net.IPAddr{IP: net.ParseIP("192.168.3.1")},
|
||||
Hostname: "",
|
||||
TTL: 0,
|
||||
RTT: 10 * time.Millisecond,
|
||||
Error: nil,
|
||||
Geo: testGeo,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestTraceroutePrinter(t *testing.T) {
|
||||
TraceroutePrinter(testResult)
|
||||
}
|
||||
|
||||
func TestTracerouteTablePrinter(t *testing.T) {
|
||||
TracerouteTablePrinter(testResult)
|
||||
}
|
||||
|
||||
func TestRealtimePrinter(t *testing.T) {
|
||||
RealtimePrinter(testResult, 0)
|
||||
RealtimePrinter(testResult, 1)
|
||||
RealtimePrinter(testResult, 2)
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func RealtimePrinter(res *trace.Result, ttl int) {
|
||||
fmt.Print(ttl)
|
||||
fmt.Print(ttl + 1)
|
||||
for i := range res.Hops[ttl] {
|
||||
HopPrinter(res.Hops[ttl][i])
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/xgadget-lab/nexttrace/ipgeo"
|
||||
|
||||
"github.com/xgadget-lab/nexttrace/trace"
|
||||
|
||||
"github.com/fatih/color"
|
||||
@@ -37,7 +39,7 @@ func TracerouteTablePrinter(res *trace.Result) {
|
||||
if data.City != "" {
|
||||
tbl.AddRow(data.Hop, data.IP, data.Latency, data.Asnumber, data.Country+", "+data.Prov+", "+data.City, data.Owner)
|
||||
} else {
|
||||
tbl.AddRow(data.Hop, data.IP, data.Latency, data.Asnumber, data.Country, data.Owner)
|
||||
tbl.AddRow(data.Hop, data.IP, data.Latency, data.Asnumber, data.Country + ", " + data.Prov, data.Owner)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -72,16 +74,18 @@ func tableDataGenerator(h trace.Hop) *rowData {
|
||||
Hop: fmt.Sprint(h.TTL),
|
||||
IP: IP,
|
||||
Latency: lantency,
|
||||
Country: "局域网",
|
||||
Owner: "腾讯云",
|
||||
Country: "LAN Address",
|
||||
Prov: "LAN Address",
|
||||
Owner: "",
|
||||
}
|
||||
} else if strings.HasPrefix(IP, "11.") {
|
||||
return &rowData{
|
||||
Hop: fmt.Sprint(h.TTL),
|
||||
IP: IP,
|
||||
Latency: lantency,
|
||||
Country: "局域网",
|
||||
Owner: "阿里云",
|
||||
Country: "LAN Address",
|
||||
Prov: "LAN Address",
|
||||
Owner: "",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +93,10 @@ func tableDataGenerator(h trace.Hop) *rowData {
|
||||
IP = fmt.Sprint(h.Hostname, " (", IP, ") ")
|
||||
}
|
||||
|
||||
if h.Geo == nil {
|
||||
h.Geo = &ipgeo.IPGeoData{}
|
||||
}
|
||||
|
||||
r := &rowData{
|
||||
Hop: fmt.Sprint(h.TTL),
|
||||
IP: IP,
|
||||
|
||||
311
quicklytest.sh
Normal file
311
quicklytest.sh
Normal file
@@ -0,0 +1,311 @@
|
||||
#!/bin/bash
|
||||
|
||||
Green_font="\033[32m" && Red_font="\033[31m" && Font_suffix="\033[0m"
|
||||
Info="${Green_font}[Info]${Font_suffix}"
|
||||
Error="${Red_font}[Error]${Font_suffix}"
|
||||
echo -e "${Green_font}
|
||||
#======================================
|
||||
# Project: NextTrace https://github.com/xgadget-lab/nexttrace
|
||||
# Copyright Notice:
|
||||
# This script is ported from @KANIKIG https://github.com/KANIKIG/
|
||||
# The developer team made some modifications to adapt to NextTrace under the GPL-3.0 LICENSE
|
||||
# NextTrace:
|
||||
# XGadget-lab Leo (leo.moe) & Vincent (vincent.moe) & zhshch (xzhsh.ch)
|
||||
# IP Geo Data Provider: LeoMoeAPI
|
||||
#======================================
|
||||
${Font_suffix}"
|
||||
|
||||
check_root() {
|
||||
[[ "$(id -u)" != "0" ]] && echo -e "${Error} must be root user !" && exit 1
|
||||
}
|
||||
|
||||
checkNexttrace() {
|
||||
if $(which nexttrace >/dev/null 2>&1); then
|
||||
echo -e "${Info} 您已安装NextTrace,是否检查更新?"
|
||||
if ask_if "输入n/y以选择:[n]"; then
|
||||
echo -e "${Info} 正在检查更新..."
|
||||
else
|
||||
return
|
||||
fi
|
||||
else
|
||||
echo -e "${Info} 您未安装NextTrace,正在开始安装..."
|
||||
mkdir -p ~/.nexttrace/
|
||||
cat >~/.nexttrace/ntraceConfig.yml <<EOF
|
||||
Token:
|
||||
LeoMoeAPI: NextTraceDemo
|
||||
IPInfo: ""
|
||||
Preference:
|
||||
AlwaysRoutePath: true
|
||||
EOF
|
||||
fi
|
||||
if curl -sL -O ${URLprefix}"https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/nt_install.sh" || curl -sL -O ${URLprefix}"https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/nt_install.sh"; then
|
||||
bash nt_install.sh #--auto #>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
getLocation() {
|
||||
echo -e "${Info} 正在获取地理位置信息..."
|
||||
countryCode=$(curl -s "http://ip-api.com/line/?fields=countryCode")
|
||||
if [ "$countryCode" == "CN" ]; then
|
||||
read -r -p "检测到国内网络环境,是否使用镜像下载以加速(n/y)[y]" input
|
||||
case $input in
|
||||
[yY][eE][sS] | [yY])
|
||||
URLprefix="https://ghproxy.com/"
|
||||
;;
|
||||
|
||||
[nN][oO] | [nN])
|
||||
URLprefix=""
|
||||
echo -e "${Info} 您选择了不使用镜像,下载可能会变得异常缓慢,或者失败"
|
||||
;;
|
||||
|
||||
*)
|
||||
URLprefix="https://ghproxy.com/"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
ask_if() {
|
||||
local choice=""
|
||||
echo -e "${Info} $1"
|
||||
read -r choice
|
||||
[[ $choice == y ]] && return 0
|
||||
return 1
|
||||
}
|
||||
|
||||
checkSystemDistribution() {
|
||||
case "$OSTYPE" in
|
||||
darwin*)
|
||||
osDistribution="darwin"
|
||||
;;
|
||||
linux*)
|
||||
osDistribution="linux"
|
||||
;;
|
||||
*)
|
||||
echo -e "${Info} unknown: $OSTYPE"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
#检查脚本更新
|
||||
check_script_update() {
|
||||
if [[ ${osDistribution} == "darwin" ]]; then
|
||||
[ "$(md5 <"${BASH_SOURCE[0]}")" == "$(curl -sL ${URLprefix}"https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/quicklytest.sh" | md5)" ] && return 1 || return 0
|
||||
else
|
||||
[ "$(md5sum "${BASH_SOURCE[0]}" | awk '{print $1}')" == "$(md5sum <(curl -sL ${URLprefix}"https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/quicklytest.sh") | awk '{print $1}')" ] && return 1 || return 0
|
||||
fi
|
||||
}
|
||||
|
||||
#更新脚本
|
||||
update_script() {
|
||||
if curl -sL -o "${BASH_SOURCE[0]}" ${URLprefix}"https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/quicklytest.sh" || curl -sL -o "${BASH_SOURCE[0]}" ${URLprefix}"https://raw.githubusercontent.com/xgadget-lab/nexttrace/main/quicklytest.sh"; then
|
||||
echo -e "${Info} quickylytest.sh更新完成,正在重启脚本..."
|
||||
exec bash "${BASH_SOURCE[0]}"
|
||||
else
|
||||
echo -e "${Info} 更新quickylytest.sh失败!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
ask_update_script() {
|
||||
if check_script_update; then
|
||||
echo -e "${Info} quickylytest.sh可升级"
|
||||
ask_if "是否升级脚本?(n/y)[n]" && update_script
|
||||
else
|
||||
echo -e "${Info} quickylytest.sh已经是最新版本"
|
||||
fi
|
||||
}
|
||||
|
||||
check_mode() {
|
||||
echo -e "${Info} Nexttrace目前支持以下三种协议发起Traceroute请求:\n1.ICMP\n2.TCP(速度最快,但部分节点不支持)\n3.UDP\n(IPv6暂只支持ICMP模式)" && read -r -p "输入数字以选择:" node
|
||||
|
||||
while [[ ! "${node}" =~ ^[1-3]$ ]]; do
|
||||
echo -e "${Error} 无效输入"
|
||||
echo -e "${Info} 请重新选择" && read -r -p "输入数字以选择:" node
|
||||
done
|
||||
|
||||
[[ "${node}" == "1" ]] && TRACECMD="nexttrace"
|
||||
[[ "${node}" == "2" ]] && TRACECMD="nexttrace -T"
|
||||
[[ "${node}" == "3" ]] && TRACECMD="nexttrace -U"
|
||||
|
||||
echo -e "${Info} 结果是否制表?(制表模式为非实时显示)"
|
||||
if ask_if "输入n/y以选择模式:[n]"; then
|
||||
TRACECMD=${TRACECMD}" -rdns -table"
|
||||
# ##Route-Path功能还未完善,临时替代:
|
||||
# [[ "${node}" == "2" ]] && TRACECMD=${TRACECMD}" -report"
|
||||
# ##
|
||||
else
|
||||
TRACECMD=${TRACECMD}" -rdns"
|
||||
# ##Route-Path功能还未完善,临时替代:
|
||||
# [[ "${node}" == "1" ]] && TRACECMD=${TRACECMD}" -report"
|
||||
# [[ "${node}" == "2" ]] && TRACECMD=${TRACECMD}" -report"
|
||||
# ##
|
||||
fi
|
||||
|
||||
# echo -e "${Info} 是否输出Route-Path?"
|
||||
# ask_if "输入n/y以选择模式:[n]" && TRACECMD=${TRACECMD}" -report"
|
||||
|
||||
}
|
||||
|
||||
test_single() {
|
||||
echo -e "${Info} 请输入你要测试的目标 ip :"
|
||||
read -r -p "输入 ip 地址:" ip
|
||||
|
||||
while [[ -z "${ip}" ]]; do
|
||||
echo -e "${Error} 无效输入"
|
||||
echo -e "${Info} 请重新输入" && read -r -p "输入 ip 地址:" ip
|
||||
done
|
||||
|
||||
${TRACECMD} "${ip}" | grep -v -E 'NextTrace|XGadget-lab|Data\ Provider'
|
||||
|
||||
repeat_test_single
|
||||
}
|
||||
|
||||
repeat_test_single() {
|
||||
echo -e "${Info} 是否继续测试其他目标 ip ?"
|
||||
if ask_if "输入n/y以选择:[n]"; then
|
||||
test_single
|
||||
else
|
||||
echo -e "${Info} 退出脚本 ..." && exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
test_alternative() {
|
||||
select_alternative
|
||||
set_alternative
|
||||
result_alternative
|
||||
}
|
||||
|
||||
select_alternative() {
|
||||
echo -e "${Info} 选择需要测速的目标网络: \n1.中国电信\n2.中国联通\n3.中国移动\n4.教育网"
|
||||
read -r -p "输入数字以选择:" ISP
|
||||
|
||||
while [[ ! "${ISP}" =~ ^[1-4]$ ]]; do
|
||||
echo -e "${Error} 无效输入"
|
||||
echo -e "${Info} 请重新选择" && read -r -p "输入数字以选择:" ISP
|
||||
done
|
||||
}
|
||||
|
||||
set_alternative() {
|
||||
[[ "${ISP}" == "1" ]] && node_1
|
||||
[[ "${ISP}" == "2" ]] && node_2
|
||||
[[ "${ISP}" == "3" ]] && node_3
|
||||
[[ "${ISP}" == "4" ]] && node_4
|
||||
}
|
||||
|
||||
node_1() {
|
||||
echo -e "1.上海电信(天翼云)\n2.厦门电信CN2\n3.北京电信\n4.江苏电信\n5.广东深圳电信\n6.广州电信(天翼云)\n7.浙江电信" && read -r -p "输入数字以选择:" node
|
||||
|
||||
while [[ ! "${node}" =~ ^[1-7]$ ]]; do
|
||||
echo -e "${Error} 无效输入"
|
||||
echo -e "${Info} 请重新选择" && read -r -p "输入数字以选择:" node
|
||||
done
|
||||
|
||||
[[ "${node}" == "1" ]] && ISP_name="上海电信" && ip=101.89.132.9
|
||||
[[ "${node}" == "2" ]] && ISP_name="厦门电信CN2" && ip=117.28.254.129
|
||||
[[ "${node}" == "3" ]] && ISP_name="北京电信" && ip=120.92.180.135
|
||||
[[ "${node}" == "4" ]] && ISP_name="江苏电信" && ip=221.229.173.233
|
||||
[[ "${node}" == "5" ]] && ISP_name="广东深圳电信" && ip=116.6.211.41
|
||||
[[ "${node}" == "6" ]] && ISP_name="广州电信(天翼云)" && ip=14.215.116.1
|
||||
[[ "${node}" == "7" ]] && ISP_name="浙江电信" && ip=115.236.169.86
|
||||
}
|
||||
|
||||
node_2() {
|
||||
echo -e "1.上海联通\n2.重庆联通\n3.北京联通\n4.安徽合肥联通\n5.江苏南京联通\n6.浙江杭州联通\n7.广东联通" && read -r -p "输入数字以选择:" node
|
||||
|
||||
while [[ ! "${node}" =~ ^[1-7]$ ]]; do
|
||||
echo -e "${Error} 无效输入"
|
||||
echo -e "${Info} 请重新选择" && read -r -p "输入数字以选择:" node
|
||||
done
|
||||
|
||||
[[ "${node}" == "1" ]] && ISP_name="上海联通" && ip=220.196.252.174
|
||||
[[ "${node}" == "2" ]] && ISP_name="重庆联通" && ip=113.207.32.65
|
||||
[[ "${node}" == "3" ]] && ISP_name="北京联通" && ip=202.106.54.150
|
||||
[[ "${node}" == "4" ]] && ISP_name="安徽合肥联通" && ip=112.122.10.26
|
||||
[[ "${node}" == "5" ]] && ISP_name="江苏联通" && ip=112.85.231.129
|
||||
[[ "${node}" == "6" ]] && ISP_name="浙江联通" && ip=60.12.214.156
|
||||
[[ "${node}" == "7" ]] && ISP_name="广东联通" && ip=58.252.2.194
|
||||
}
|
||||
|
||||
node_3() {
|
||||
echo -e "1.上海移动\n2.四川成都移动\n3.北京移动\n4.浙江杭州移动\n5.广东移动\n6.江苏移动\n7.浙江移动" && read -r -p "输入数字以选择:" node
|
||||
|
||||
while [[ ! "${node}" =~ ^[1-7]$ ]]; do
|
||||
echo -e "${Error} 无效输入"
|
||||
echo -e "${Info} 请重新选择" && read -r -p "输入数字以选择:" node
|
||||
done
|
||||
|
||||
[[ "${node}" == "1" ]] && ISP_name="上海移动" && ip=117.184.42.114
|
||||
[[ "${node}" == "2" ]] && ISP_name="四川成都移动" && ip=183.221.247.9
|
||||
[[ "${node}" == "3" ]] && ISP_name="北京移动" && ip=111.13.217.125
|
||||
[[ "${node}" == "4" ]] && ISP_name="浙江移动" && ip=183.246.69.139
|
||||
[[ "${node}" == "5" ]] && ISP_name="广东移动" && ip=221.179.44.57
|
||||
[[ "${node}" == "6" ]] && ISP_name="江苏移动" && ip=120.195.6.129
|
||||
[[ "${node}" == "7" ]] && ISP_name="浙江移动" && ip=183.246.69.139
|
||||
}
|
||||
|
||||
node_4() {
|
||||
ISP_name="北京教育网" && ip=211.68.69.240
|
||||
}
|
||||
|
||||
result_alternative() {
|
||||
echo -e "${Info} 测试路由 到 ${ISP_name} 中 ..."
|
||||
${TRACECMD} ${ip} | grep -v -E 'NextTrace|XGadget-lab|Data\ Provider'
|
||||
echo -e "${Info} 测试路由 到 ${ISP_name} 完成 !"
|
||||
|
||||
repeat_test_alternative
|
||||
}
|
||||
|
||||
repeat_test_alternative() {
|
||||
echo -e "${Info} 是否继续测试其他节点?"
|
||||
if ask_if "输入n/y以选择:[n]"; then
|
||||
test_alternative
|
||||
else
|
||||
echo -e "${Info} 退出脚本 ..." && exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
test_all() {
|
||||
result_all '116.6.211.41' '广东东莞CN2'
|
||||
|
||||
result_all '101.95.110.149' '上海电信'
|
||||
|
||||
result_all '112.85.231.129' '江苏徐州联通'
|
||||
|
||||
result_all '120.199.239.1' '浙江杭州移动'
|
||||
|
||||
result_all '211.68.69.240' '北京教育网'
|
||||
|
||||
echo -e "${Info} 四网路由快速测试 已完成 !"
|
||||
}
|
||||
|
||||
result_all() {
|
||||
ISP_name=$2
|
||||
echo -e "${Info} 测试路由 到 ${ISP_name} 中 ..."
|
||||
${TRACECMD} "${1}" | grep -v -E 'NextTrace|XGadget-lab|Data\ Provider'
|
||||
echo -e "${Info} 测试路由 到 ${ISP_name} 完成 !"
|
||||
}
|
||||
|
||||
check_root
|
||||
checkSystemDistribution
|
||||
getLocation
|
||||
ask_update_script
|
||||
checkNexttrace
|
||||
check_mode
|
||||
echo -e "${Info} 选择你要使用的功能: "
|
||||
echo -e "1.选择一个节点进行测试\n2.四网路由快速测试\n3.手动输入 ip 进行测试"
|
||||
read -r -p "输入数字以选择:" function
|
||||
|
||||
while [[ ! "${function}" =~ ^[1-3]$ ]]; do
|
||||
echo -e "${Error} 缺少或无效输入"
|
||||
echo -e "${Info} 请重新选择" && read -r -p "输入数字以选择:" function
|
||||
done
|
||||
|
||||
if [[ "${function}" == "1" ]]; then
|
||||
test_alternative
|
||||
elif [[ "${function}" == "2" ]]; then
|
||||
test_all
|
||||
else
|
||||
test_single
|
||||
fi
|
||||
@@ -1,10 +1,10 @@
|
||||
package reporter
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/xgadget-lab/nexttrace/ipgeo"
|
||||
"github.com/xgadget-lab/nexttrace/trace"
|
||||
@@ -24,9 +24,12 @@ func New(rs *trace.Result, ip string) Reporter {
|
||||
}
|
||||
|
||||
type reporter struct {
|
||||
targetIP string
|
||||
routeReport map[uint16][]routeReportNode
|
||||
routeResult *trace.Result
|
||||
targetTTL uint16
|
||||
targetIP string
|
||||
routeReport map[uint16][]routeReportNode
|
||||
routeReportLock sync.Mutex
|
||||
routeResult *trace.Result
|
||||
wg sync.WaitGroup
|
||||
}
|
||||
|
||||
type routeReportNode struct {
|
||||
@@ -40,71 +43,115 @@ func experimentTag() {
|
||||
fmt.Println("Route-Path 功能实验室")
|
||||
}
|
||||
|
||||
func (r *reporter) generateRouteReportNode(ip string, ipGeoData ipgeo.IPGeoData) (routeReportNode, error) {
|
||||
rpn := routeReportNode{}
|
||||
go func() {
|
||||
ptr, err := net.LookupAddr(ip)
|
||||
if err == nil {
|
||||
if strings.Contains(strings.ToLower(ptr[0]), "ix") {
|
||||
rpn.ix = true
|
||||
} else {
|
||||
rpn.ix = false
|
||||
}
|
||||
}
|
||||
}()
|
||||
func (r *reporter) generateRouteReportNode(ip string, ipGeoData ipgeo.IPGeoData, ttl uint16) {
|
||||
|
||||
var success bool = true
|
||||
|
||||
defer r.wg.Done()
|
||||
|
||||
rpn := routeReportNode{}
|
||||
ptr, err := net.LookupAddr(ip)
|
||||
|
||||
if err == nil {
|
||||
if strings.Contains(strings.ToLower(ptr[0]), "ix") {
|
||||
rpn.ix = true
|
||||
} else {
|
||||
rpn.ix = false
|
||||
}
|
||||
}
|
||||
// TODO: 这种写法不好,后面再重构一下
|
||||
// 判断反向解析的域名中又或者是IP地理位置数据库中,是否出现了 IX
|
||||
if strings.Contains(strings.ToLower(ipGeoData.Isp), "exchange") || strings.Contains(strings.ToLower(ipGeoData.Isp), "ix") || strings.Contains(strings.ToLower(ipGeoData.Owner), "exchange") || strings.Contains(strings.ToLower(ipGeoData.Owner), "ix") {
|
||||
rpn.ix = true
|
||||
}
|
||||
|
||||
// TODO: 正则判断POP并且提取带宽大小等信息
|
||||
|
||||
// CN2 需要特殊处理,因为他们很多没有ASN
|
||||
// 但是目前这种写法是不规范的,属于凭空标记4809的IP
|
||||
// TODO: 用更好的方式显示 CN2 骨干网的路由 Path
|
||||
if strings.HasPrefix(ip, "59.43") {
|
||||
rpn.asn = "4809"
|
||||
} else {
|
||||
rpn.asn = ipGeoData.Asnumber
|
||||
}
|
||||
|
||||
// 无论最后一跳是否为存在地理位置信息(AnyCast),都应该给予显示
|
||||
if ipGeoData.Country == "" || ipGeoData.City == "" || ipGeoData.City == "-" && ip != r.targetIP {
|
||||
return rpn, errors.New("GeoData Search Failed")
|
||||
if (ipGeoData.Country == "" || ipGeoData.Country == "LAN Address" || ipGeoData.Country == "-") && ip != r.targetIP {
|
||||
success = false
|
||||
} else {
|
||||
if ipGeoData.City == "" {
|
||||
rpn.geo = []string{ipGeoData.Country, ipGeoData.Country}
|
||||
rpn.geo = []string{ipGeoData.Country, ipGeoData.Prov}
|
||||
} else {
|
||||
rpn.geo = []string{ipGeoData.Country, ipGeoData.City}
|
||||
}
|
||||
}
|
||||
if ipGeoData.Asnumber == "" {
|
||||
rpn.asn = "*"
|
||||
}
|
||||
|
||||
if ipGeoData.Isp == "" {
|
||||
rpn.isp = ipGeoData.Owner
|
||||
} else {
|
||||
rpn.isp = ipGeoData.Isp
|
||||
}
|
||||
return rpn, nil
|
||||
|
||||
// 有效记录
|
||||
if success {
|
||||
// 锁住资源,防止同时写panic
|
||||
r.routeReportLock.Lock()
|
||||
// 添加到MAP中
|
||||
r.routeReport[ttl] = append(r.routeReport[ttl], rpn)
|
||||
// 写入完成,解锁释放资源给其他协程
|
||||
r.routeReportLock.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
func (r *reporter) InitialBaseData() Reporter {
|
||||
var nodeIndex uint16 = 1
|
||||
reportNodes := map[uint16][]routeReportNode{}
|
||||
for i := uint16(0); int(i) < len(r.routeResult.Hops); i++ {
|
||||
|
||||
r.routeReport = reportNodes
|
||||
r.targetTTL = uint16(len(r.routeResult.Hops))
|
||||
|
||||
for i := uint16(0); i < r.targetTTL; i++ {
|
||||
traceHop := r.routeResult.Hops[i][0]
|
||||
if traceHop.Success {
|
||||
currentIP := traceHop.Address.String()
|
||||
rpn, err := r.generateRouteReportNode(currentIP, *traceHop.Geo)
|
||||
if err == nil {
|
||||
reportNodes[nodeIndex] = append(reportNodes[nodeIndex], rpn)
|
||||
nodeIndex += 1
|
||||
}
|
||||
r.wg.Add(1)
|
||||
go r.generateRouteReportNode(currentIP, *traceHop.Geo, i)
|
||||
}
|
||||
}
|
||||
r.routeReport = reportNodes
|
||||
|
||||
// 等待所有的子协程运行完毕
|
||||
r.wg.Wait()
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *reporter) Print() {
|
||||
var beforeActiveTTL uint16 = 0
|
||||
r.InitialBaseData()
|
||||
for i := uint16(1); int(i) < len(r.routeReport)+1; i++ {
|
||||
// 尝试首个有效 TTL
|
||||
for i := uint16(0); i < r.targetTTL; i++ {
|
||||
if len(r.routeReport[i]) != 0 {
|
||||
beforeActiveTTL = i
|
||||
// 找到以后便不再循环
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for i := beforeActiveTTL; i < r.targetTTL; i++ {
|
||||
// 计算该TTL内的数据长度,如果为0,则代表没有有效数据
|
||||
if len(r.routeReport[i]) == 0 {
|
||||
// 跳过改跃点的数据整理
|
||||
continue
|
||||
}
|
||||
nodeReport := r.routeReport[i][0]
|
||||
if i == 1 {
|
||||
|
||||
if i == beforeActiveTTL {
|
||||
fmt.Printf("AS%s %s「%s『%s", nodeReport.asn, nodeReport.isp, nodeReport.geo[0], nodeReport.geo[1])
|
||||
} else {
|
||||
nodeReportBefore := r.routeReport[i-1][0]
|
||||
nodeReportBefore := r.routeReport[beforeActiveTTL][0]
|
||||
// ASN 相同,同个 ISP 内部的数据传递
|
||||
if nodeReportBefore.asn == nodeReport.asn {
|
||||
// Same ASN but Coutry or City Changed
|
||||
if nodeReportBefore.geo[0] != nodeReport.geo[0] {
|
||||
@@ -115,8 +162,11 @@ func (r *reporter) Print() {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// ASN 不同,跨 ISP 的数据传递,这里可能会出现 POP、IP Transit、Peer、Exchange
|
||||
fmt.Printf("』」")
|
||||
if int(i) != len(r.routeReport)+1 {
|
||||
// 部分 Shell 客户端可能无法很好的展示这个特殊字符
|
||||
// TODO: 寻找其他替代字符
|
||||
fmt.Printf("\n ╭╯\n ╰")
|
||||
}
|
||||
if nodeReport.ix {
|
||||
@@ -126,6 +176,8 @@ func (r *reporter) Print() {
|
||||
}
|
||||
}
|
||||
}
|
||||
// 标记为最新的一个有效跃点
|
||||
beforeActiveTTL = i
|
||||
}
|
||||
fmt.Println("』」")
|
||||
}
|
||||
|
||||
@@ -1,31 +1,115 @@
|
||||
package reporter
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/xgadget-lab/nexttrace/ipgeo"
|
||||
"github.com/xgadget-lab/nexttrace/trace"
|
||||
"github.com/xgadget-lab/nexttrace/util"
|
||||
)
|
||||
|
||||
var testResult = &trace.Result{
|
||||
Hops: [][]trace.Hop{
|
||||
{
|
||||
{
|
||||
Success: true,
|
||||
Address: &net.IPAddr{IP: net.ParseIP("192.168.3.1")},
|
||||
Hostname: "test",
|
||||
TTL: 0,
|
||||
RTT: 10 * time.Millisecond,
|
||||
Error: nil,
|
||||
Geo: &ipgeo.IPGeoData{
|
||||
Asnumber: "4808",
|
||||
Country: "中国",
|
||||
Prov: "北京市",
|
||||
City: "北京市",
|
||||
District: "北京市",
|
||||
Owner: "",
|
||||
Isp: "中国联通",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
Success: true,
|
||||
Address: &net.IPAddr{IP: net.ParseIP("114.249.16.1")},
|
||||
Hostname: "test",
|
||||
TTL: 0,
|
||||
RTT: 10 * time.Millisecond,
|
||||
Error: nil,
|
||||
Geo: &ipgeo.IPGeoData{
|
||||
Asnumber: "4808",
|
||||
Country: "中国",
|
||||
Prov: "北京市",
|
||||
City: "北京市",
|
||||
District: "北京市",
|
||||
Owner: "",
|
||||
Isp: "中国联通",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
Success: true,
|
||||
Address: &net.IPAddr{IP: net.ParseIP("219.158.5.150")},
|
||||
Hostname: "test",
|
||||
TTL: 0,
|
||||
RTT: 10 * time.Millisecond,
|
||||
Error: nil,
|
||||
Geo: &ipgeo.IPGeoData{
|
||||
Asnumber: "4837",
|
||||
Country: "中国",
|
||||
Prov: "",
|
||||
City: "",
|
||||
District: "",
|
||||
Owner: "",
|
||||
Isp: "中国联通",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
Success: true,
|
||||
Address: &net.IPAddr{IP: net.ParseIP("62.115.125.160")},
|
||||
Hostname: "test",
|
||||
TTL: 0,
|
||||
RTT: 10 * time.Millisecond,
|
||||
Error: nil,
|
||||
Geo: &ipgeo.IPGeoData{
|
||||
Asnumber: "1299",
|
||||
Country: "Sweden",
|
||||
Prov: "Stockholm County",
|
||||
City: "Stockholm",
|
||||
District: "",
|
||||
Owner: "",
|
||||
Isp: "Telia Company AB",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
Success: true,
|
||||
Address: &net.IPAddr{IP: net.ParseIP("213.226.68.73")},
|
||||
Hostname: "test",
|
||||
TTL: 0,
|
||||
RTT: 10 * time.Millisecond,
|
||||
Error: nil,
|
||||
Geo: &ipgeo.IPGeoData{
|
||||
Asnumber: "56630",
|
||||
Country: "Germany",
|
||||
Prov: "Hesse, Frankfurt",
|
||||
City: "",
|
||||
District: "",
|
||||
Owner: "",
|
||||
Isp: "Melbikomas UAB",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestPrint(t *testing.T) {
|
||||
ip := util.DomainLookUp("213.226.68.73")
|
||||
var m trace.Method = "tcp"
|
||||
var conf = trace.Config{
|
||||
DestIP: ip,
|
||||
DestPort: 80,
|
||||
MaxHops: 30,
|
||||
NumMeasurements: 1,
|
||||
ParallelRequests: 1,
|
||||
RDns: true,
|
||||
IPGeoSource: ipgeo.GetSource("LeoMoeAPI"),
|
||||
Timeout: 2 * time.Second,
|
||||
|
||||
//Quic: false,
|
||||
}
|
||||
|
||||
res, _ := trace.Traceroute(m, conf)
|
||||
r := New(res, ip.String())
|
||||
r := New(testResult, "213.226.68.73")
|
||||
r.Print()
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package signal
|
||||
|
||||
type Signal struct {
|
||||
sigChan chan struct{}
|
||||
}
|
||||
|
||||
func New() *Signal {
|
||||
return &Signal{sigChan: make(chan struct{}, 1)}
|
||||
}
|
||||
|
||||
func (s *Signal) Signal() {
|
||||
if len(s.sigChan) == 0 {
|
||||
s.sigChan <- struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Signal) Chan() chan struct{} {
|
||||
return s.sigChan
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package taskgroup
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
type TaskGroup struct {
|
||||
count int
|
||||
mu sync.Mutex
|
||||
done []chan struct{}
|
||||
}
|
||||
|
||||
func New() *TaskGroup {
|
||||
return &TaskGroup{
|
||||
count: 0,
|
||||
mu: sync.Mutex{},
|
||||
done: []chan struct{}{},
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TaskGroup) Add() {
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
t.count++
|
||||
}
|
||||
|
||||
func (t *TaskGroup) Done() {
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
if t.count-1 == 0 {
|
||||
for _, doneChannel := range t.done {
|
||||
doneChannel <- struct{}{}
|
||||
}
|
||||
t.done = []chan struct{}{}
|
||||
}
|
||||
t.count--
|
||||
}
|
||||
|
||||
func (t *TaskGroup) Wait() {
|
||||
doneChannel := make(chan struct{})
|
||||
t.mu.Lock()
|
||||
t.done = append(t.done, doneChannel)
|
||||
t.mu.Unlock()
|
||||
<-doneChannel
|
||||
}
|
||||
@@ -74,19 +74,26 @@ func (t *ICMPTracer) listenICMP() {
|
||||
if msg.N == nil {
|
||||
continue
|
||||
}
|
||||
rm, err := icmp.ParseMessage(1, msg.Msg[:*msg.N])
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
continue
|
||||
}
|
||||
switch rm.Type {
|
||||
case ipv4.ICMPTypeTimeExceeded:
|
||||
t.handleICMPMessage(msg, 0, rm.Body.(*icmp.TimeExceeded).Data)
|
||||
case ipv4.ICMPTypeEchoReply:
|
||||
t.handleICMPMessage(msg, 1, rm.Body.(*icmp.Echo).Data)
|
||||
default:
|
||||
// log.Println("received icmp message of unknown type", rm.Type)
|
||||
// 抢在ICMP解析包之前先判断是否和目的地IP一致
|
||||
// Leo 注释:我是伞兵,traceroute 居然忘了做包校验...
|
||||
dstip := net.IP(msg.Msg[24:28])
|
||||
if dstip.Equal(t.DestIP) || dstip.Equal(net.IPv4zero) {
|
||||
// 匹配再继续解析包,否则直接丢弃
|
||||
rm, err := icmp.ParseMessage(1, msg.Msg[:*msg.N])
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
continue
|
||||
}
|
||||
switch rm.Type {
|
||||
case ipv4.ICMPTypeTimeExceeded:
|
||||
t.handleICMPMessage(msg, 0, rm.Body.(*icmp.TimeExceeded).Data)
|
||||
case ipv4.ICMPTypeEchoReply:
|
||||
t.handleICMPMessage(msg, 1, rm.Body.(*icmp.Echo).Data)
|
||||
default:
|
||||
// log.Println("received icmp message of unknown type", rm.Type)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
"github.com/google/gopacket"
|
||||
"github.com/google/gopacket/layers"
|
||||
"github.com/xgadget-lab/nexttrace/listener_channel"
|
||||
"github.com/xgadget-lab/nexttrace/util"
|
||||
"golang.org/x/net/context"
|
||||
"golang.org/x/net/icmp"
|
||||
@@ -89,18 +88,21 @@ func (t *TCPTracer) listenICMP() {
|
||||
if msg.N == nil {
|
||||
continue
|
||||
}
|
||||
rm, err := icmp.ParseMessage(1, msg.Msg[:*msg.N])
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
continue
|
||||
}
|
||||
switch rm.Type {
|
||||
case ipv4.ICMPTypeTimeExceeded:
|
||||
t.handleICMPMessage(msg, rm.Body.(*icmp.TimeExceeded).Data)
|
||||
case ipv4.ICMPTypeDestinationUnreachable:
|
||||
t.handleICMPMessage(msg, rm.Body.(*icmp.DstUnreach).Data)
|
||||
default:
|
||||
//log.Println("received icmp message of unknown type", rm.Type)
|
||||
dstip := net.IP(msg.Msg[24:28])
|
||||
if dstip.Equal(t.DestIP) {
|
||||
rm, err := icmp.ParseMessage(1, msg.Msg[:*msg.N])
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
continue
|
||||
}
|
||||
switch rm.Type {
|
||||
case ipv4.ICMPTypeTimeExceeded:
|
||||
t.handleICMPMessage(msg, rm.Body.(*icmp.TimeExceeded).Data)
|
||||
case ipv4.ICMPTypeDestinationUnreachable:
|
||||
t.handleICMPMessage(msg, rm.Body.(*icmp.DstUnreach).Data)
|
||||
default:
|
||||
//log.Println("received icmp message of unknown type", rm.Type)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,10 +112,7 @@ func (t *TCPTracer) listenICMP() {
|
||||
// @title listenTCP
|
||||
// @description 监听TCP的响应数据包
|
||||
func (t *TCPTracer) listenTCP() {
|
||||
lc := listener_channel.New(t.tcp)
|
||||
|
||||
defer lc.Stop()
|
||||
|
||||
lc := NewPacketListener(t.tcp, t.ctx)
|
||||
go lc.Start()
|
||||
|
||||
for {
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
"github.com/google/gopacket"
|
||||
"github.com/google/gopacket/layers"
|
||||
"github.com/xgadget-lab/nexttrace/listener_channel"
|
||||
"github.com/xgadget-lab/nexttrace/util"
|
||||
"golang.org/x/net/context"
|
||||
"golang.org/x/net/icmp"
|
||||
@@ -111,10 +110,7 @@ func (t *TCPTracerv6) listenICMP() {
|
||||
// @title listenTCP
|
||||
// @description 监听TCP的响应数据包
|
||||
func (t *TCPTracerv6) listenTCP() {
|
||||
lc := listener_channel.New(t.tcp)
|
||||
|
||||
defer lc.Stop()
|
||||
|
||||
lc := NewPacketListener(t.tcp, t.ctx)
|
||||
go lc.Start()
|
||||
|
||||
for {
|
||||
|
||||
@@ -39,11 +39,11 @@ func formatIpGeoData(ip string, data *ipgeo.IPGeoData) string {
|
||||
// TODO: 判断阿里云和腾讯云内网,数据不足,有待进一步完善
|
||||
// TODO: 移动IDC判断到Hop.fetchIPData函数,减少API调用
|
||||
if strings.HasPrefix(ip, "9.") {
|
||||
res = append(res, "局域网", "腾讯云")
|
||||
res = append(res, "LAN Address", "")
|
||||
} else if strings.HasPrefix(ip, "11.") {
|
||||
res = append(res, "局域网", "阿里云")
|
||||
res = append(res, "LAN Address", "")
|
||||
} else if data.Country == "" {
|
||||
res = append(res, "局域网")
|
||||
res = append(res, "LAN Address")
|
||||
} else {
|
||||
// 有些IP的归属信息为空,这个时候将ISP的信息填入
|
||||
if data.Owner == "" {
|
||||
|
||||
Reference in New Issue
Block a user