Compare commits

...

37 Commits

Author SHA1 Message Date
tsosunchia
d690f680f5 增加一些平台支持 2022-05-28 02:29:18 +08:00
tsosunchia
e96686013d 增加一些平台支持 2022-05-28 02:07:45 +08:00
tsosunchia
6726b55fc9 Update .cross_compile.sh 2022-05-28 01:58:23 +08:00
tsosunchia
9f29c75491 增加一些平台支持 2022-05-28 01:51:30 +08:00
tsosunchia
2f5bf3f195 优化提示 2022-05-28 00:40:37 +08:00
tsosunchia
5981e82ee3 fix some bugs 2022-05-28 00:31:58 +08:00
tsosunchia
80f7857a65 Merge pull request #30 from tsosunchia/main
fix some bugs
2022-05-27 23:44:14 +08:00
tsosunchia
700d38de1c fix some bugs 2022-05-27 23:43:21 +08:00
tsosunchia
2dbf3f04a4 Merge pull request #29 from tsosunchia/main
fix some bugs
2022-05-27 23:10:46 +08:00
tsosunchia
45df06ea80 fix some bugs 2022-05-27 23:10:07 +08:00
tsosunchia
98953048ce fix some bugs 2022-05-27 22:54:07 +08:00
tsosunchia
eddd4226b0 Merge pull request #28 from tsosunchia/main
修补BUG
2022-05-27 22:45:55 +08:00
tsosunchia
5afd9eb09e Merge remote-tracking branch 'refs/remotes/origin/main' 2022-05-27 22:43:55 +08:00
tsosunchia
70006aaa13 优化逻辑结构 2022-05-27 22:43:28 +08:00
tsosunchia
497fb647c0 Merge pull request #27 from tsosunchia/main
优化逻辑结构
2022-05-27 22:31:44 +08:00
tsosunchia
be8552c3cd 优化逻辑结构 2022-05-27 22:30:54 +08:00
sjlleo
f320fd6202 update: 优化逻辑,废弃 realtime 参数 2022-05-27 21:27:26 +08:00
sjlleo
a42c5e3734 update: ttl 从 1 开始 2022-05-27 21:26:47 +08:00
sjlleo
e6480c84e0 Revert "update: 优化打印逻辑,废除 realtime 参数"
This reverts commit 126115c04e.
2022-05-27 21:14:16 +08:00
sjlleo
126115c04e update: 优化打印逻辑,废除 realtime 参数 2022-05-27 21:08:30 +08:00
tsosunchia
ea7fd2af0f Update quicklytest.sh 2022-05-27 19:55:54 +08:00
tsosunchia
3fc81f4e71 Merge pull request #26 from tsosunchia/main
修补之前再部分macOS设备出现的颜色显示问题:替换macOS中bash-3.1不支持的部分指令
2022-05-27 19:37:55 +08:00
tsosunchia
0c2b77bd81 Merge branch 'main' into main 2022-05-27 19:37:48 +08:00
tsosunchia
ac33c086c6 修补之前再部分macOS设备出现的颜色显示问题:替换macOS中bash-3.1不支持的部分指令 2022-05-27 19:34:35 +08:00
zhshch2002
fadfdc87d4 fix: nt_install.sh red color 2022-05-27 19:31:38 +08:00
tsosunchia
eb77a2b69b Merge pull request #25 from tsosunchia/main
替换macOS中bash-3.1不支持的部分指令
2022-05-27 19:14:44 +08:00
tsosunchia
02e6c6e1bf 替换macOS中bash-3.1不支持的部分指令 2022-05-27 19:13:05 +08:00
tsosunchia
838af3b7a1 Merge pull request #24 from tsosunchia/main
替换macOS下bash-3.1不兼容的部分指令 issues#21
2022-05-27 19:10:10 +08:00
tsosunchia
7cd16036a6 替换macOS中bash-3.1不支持的部分指令 2022-05-27 19:08:04 +08:00
tsosunchia
2ef4f61d7b Merge branch 'xgadget-lab:main' into main 2022-05-27 18:32:46 +08:00
tsosunchia
688622738f 整理排版 2022-05-27 18:32:23 +08:00
tsosunchia
83fe583f2a Merge pull request #23 from tsosunchia/main
fix some bugs
2022-05-27 18:30:49 +08:00
tsosunchia
4b32594c17 fix some bugs 2022-05-27 18:30:18 +08:00
tsosunchia
927b6d4035 Merge pull request #22 from tsosunchia/main
修正macOS下缺少md5sum导致的运行问题  issues#21
2022-05-27 18:16:59 +08:00
tsosunchia
aa651f30cc Merge branch 'xgadget-lab:main' into main 2022-05-27 18:15:38 +08:00
tsosunchia
ffec9a93cd update nt_install.sh 修正macOS下缺少md5sum导致的运行问题 issues#21 2022-05-27 18:15:10 +08:00
sjlleo
59a744b3b5 update: 修正文档里面有一个route-path错位的问题 2022-05-27 18:13:37 +08:00
7 changed files with 433 additions and 391 deletions

View File

@@ -5,7 +5,7 @@ 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')"
@@ -38,3 +38,23 @@ for pl in ${PLATFORMS}; do
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

View File

@@ -36,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 }}

View File

@@ -40,8 +40,6 @@ nexttrace 1.0.0.1
# 表格打印一次性输出全部跳数需等待20-40秒
nexttrace -table 1.0.0.1
# 实时打印 (-realtime与-table不能同时选择)
nexttrace -realtime 1.0.0.1
# IPv6 ICMP Trace
nexttrace 2606:4700:4700::1111
@@ -78,15 +76,15 @@ nexttrace -rdns www.bbix.net
# 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』」
# ╰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`
`NextTrace`支持用户自主选择 IP 数据库(目前支持:`LeoMoeAPI`, `IP.SB`, `IPInfo`, `IPInsight`, `IPAPI.com`
```bash
# 可以自行指定IP数据库[此处为IP.SB]不指定则默认为LeoMoeAPI
@@ -94,14 +92,15 @@ 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 -table 1.1.1.1
nexttrace -T -q 2 -r 1 -rdns -realtime -report 2001:4860:4860::8888
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 数据库
@@ -122,7 +121,7 @@ Options:
-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")
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
@@ -133,8 +132,6 @@ Options:
Set ParallelRequests number. It should be 1 when there is a multi-routing. (default 18)
-rdns
Set whether rDNS will be display
-realtime
Output trace results in runtime
-table
Output trace results as table
-report

28
main.go
View File

@@ -22,15 +22,14 @@ var port = flag.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]")
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 realtimePrint = fSet.Bool("realtime", false, "Output trace results in runtime")
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] [ -realtime | -table ] -report")
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)
}
@@ -105,25 +104,14 @@ func main() {
log.Fatalln(err)
}
if (*tcpSYNFlag && *udpPackageFlag) || *tablePrint {
printer.TracerouteTablePrinter(res)
} else if *tcpSYNFlag || *udpPackageFlag {
printer.TraceroutePrinter(res)
}
if *routePath {
// 如果为TCP SYN也打印路由跟踪结果
if *tcpSYNFlag {
printer.TracerouteTablePrinter(res)
}
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)
}
}
}

View File

@@ -3,253 +3,258 @@
auto=False
#是否忽略一切警告,按默认执行
if [[ $1 == "--auto" ]]; then
auto=True
echo "自动运行中"
auto=True
echo "自动运行中"
fi
usrPath="/usr/local/bin"
function red() {
echo -e "\e[1;31m$1\e[0m"
echo -e "\033[31m""${1}""\033[0m"
}
checkRootPermit() {
[[ $EUID -ne 0 ]] && red "请使用sudo/root权限运行本脚本" && exit 1
}
ask_if() {
local choice=""
while [ "$choice" != "y" ] && [ "$choice" != "n" ]; do
red $1
read choice
done
[ $choice == y ] && return 0
return 1
}
#检查脚本更新
check_script_update() {
[ "$(md5sum "${BASH_SOURCE[0]}" | awk '{print $1}')" == "$(md5sum <(curl -sL "https://github.com/xgadget-lab/nexttrace/raw/main/nt_install.sh") | awk '{print $1}')" ] && return 1 || return 0
}
#更新脚本
update_script() {
if curl -sL -o "${BASH_SOURCE[0]}" "https://github.com/xgadget-lab/nexttrace/raw/main/nt_install.sh" || curl -sL -o "${BASH_SOURCE[0]}" "https://github.com/xgadget-lab/nexttrace/raw/main/nt_install.sh"; then
red "脚本更新完成,正在重启脚本..."
exec bash ${BASH_SOURCE[0]} --auto
else
red "更新脚本失败!"
exit 1
fi
}
ask_update_script() {
if check_script_update; then
red "脚本可升级"
[[ $auto == True ]] && update_script
ask_if "是否升级脚本?(y/n)" && update_script
else
red "脚本已经是最新版本"
fi
[[ $EUID -ne 0 ]] && red "请使用sudo/root权限运行本脚本" && exit 1
}
checkSystemArch() {
arch=$(uname -m)
case $arch in
'x86_64')
archParam='amd64'
;;
'mips')
archParam='mips'
;;
'arm64' | 'aarch64')
archParam="arm64"
;;
*)
red "未知的系统架构,请联系开发者."
exit 1
;;
esac
arch=$(uname -m)
case $arch in
'x86_64')
archParam='amd64'
;;
'mips')
archParam='mips'
;;
'arm64' | 'aarch64')
archParam="arm64"
;;
*)
red "未知的系统架构,请联系开发者."
exit 1
;;
esac
}
checkSystemDistribution() {
case "$OSTYPE" in
darwin*)
osDistribution="darwin"
downPath="/var/tmp/nexttrace"
;;
linux*)
osDistribution="linux"
downPath="/var/tmp/nexttrace"
;;
*)
red "unknown: $OSTYPE"
exit 1
;;
esac
case "$OSTYPE" in
darwin*)
osDistribution="darwin"
downPath="/var/tmp/nexttrace"
;;
linux*)
osDistribution="linux"
downPath="/var/tmp/nexttrace"
;;
*)
red "unknown: $OSTYPE"
exit 1
;;
esac
}
ask_if() {
local choice=""
red "${1}"
read -r choice
[[ $choice == y ]] && return 0 || return 1
}
#检查脚本更新
check_script_update() {
if [[ ${osDistribution} == "darwin" ]]; then
[ "$(md5 <"${BASH_SOURCE[0]}")" == "$(curl -sL "https://github.com/xgadget-lab/nexttrace/raw/main/nt_install.sh" | md5)" ] && return 1 || return 0
else
[ "$(md5sum "${BASH_SOURCE[0]}" | awk '{print $1}')" == "$(md5sum <(curl -sL "https://github.com/xgadget-lab/nexttrace/raw/main/nt_install.sh") | awk '{print $1}')" ] && return 1 || return 0
fi
}
#更新脚本
update_script() {
if curl -sL -o "${BASH_SOURCE[0]}" "https://github.com/xgadget-lab/nexttrace/raw/main/nt_install.sh" || curl -sL -o "${BASH_SOURCE[0]}" "https://github.com/xgadget-lab/nexttrace/raw/main/nt_install.sh"; then
red "nt_install.sh更新完成正在重启脚本..."
exec bash "${BASH_SOURCE[0]}" --auto
else
red "更新nt_install.sh失败"
exit 1
fi
}
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
}
getLocation() {
red "正在获取地理位置信息..."
countryCode=$(curl -s "http://ip-api.com/line/?fields=countryCode")
red "正在获取地理位置信息..."
countryCode=$(curl -s "http://ip-api.com/line/?fields=countryCode")
}
checkPackageManger() {
if [[ "$(which brew)" ]]; then #务必将brew置于第一位,macOS的apt是假的
# brew update
PACKAGE_MANAGEMENT_INSTALL='brew install'
PACKAGE_MANAGEMENT_REMOVE='brew uninstall'
elif [[ "$(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
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
}
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
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() {
nexttrace -h &>/dev/null
if [ $? -ne 0 ]; then
return 0
fi
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}') &>/dev/null
if [[ $currentVersion == $version ]]; then
red "当前版本已是最新版本"
exit 0
fi
red 当前最新release版本${version}
red 您当前的版本:${currentVersion}
if [[ $auto == True ]]; then
return 0
fi
read -r -p "是否更新软件? (y/n)" input
case $input in
[yY][eE][sS] | [yY])
return 0
;;
[nN][oO] | [nN])
red "您选择了取消更新,脚本即将退出"
exit 1
;;
*)
return 0
;;
esac
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() {
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:-1}
if [ "$countryCode" == "CN" ]; then
if [[ $auto == True ]]; then
latestURL="https://ghproxy.com/"$latestURL
else
read -r -p "检测到国内网络环境,是否使用镜像下载以加速(y/n)" input
case $input in
[yY][eE][sS] | [yY])
latestURL="https://ghproxy.com/"$latestURL
;;
[nN][oO] | [nN])
red "您选择了不使用镜像,下载可能会变得异常缓慢,或者失败"
;;
*)
latestURL="https://ghproxy.com/"$latestURL
;;
esac
fi
fi
red "正在下载 NextTrace 二进制文件..."
wget -O ${downPath} ${latestURL} &>/dev/null
if [ $? -eq 0 ]; then
red "NextTrace 现在已经在您的系统中可用"
changeMode
mv ${downPath} ${usrPath}
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
red "NextTrace 下载失败,请检查您的网络是否正常"
exit 1
read -r -p "检测到国内网络环境,是否使用镜像下载以加速(n/y)[y]" input
case $input in
[yY][eE][sS] | [yY])
latestURL="https://ghproxy.com/"$latestURL
;;
[nN][oO] | [nN])
red "您选择了不使用镜像,下载可能会变得异常缓慢,或者失败"
;;
*)
latestURL="https://ghproxy.com/"$latestURL
;;
esac
fi
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
[[ ${osDistribution} == "darwin" ]] && xattr -r -d com.apple.quarantine ${downPath}
chmod +x ${downPath}
[[ ${osDistribution} == "darwin" ]] && xattr -r -d com.apple.quarantine ${downPath}
}
runBinrayFileHelp() {
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"
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 "是否添加自动更新任务?(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 0
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
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
ask_update_script
checkSystemDistribution
checkSystemArch
ask_update_script
checkPackageManger
install_software wget
install_software jq

View File

@@ -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])
}

View File

@@ -1,6 +1,5 @@
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
Green_font="\033[32m" && Red_font="\033[31m" && Font_suffix="\033[0m"
Info="${Green_font}[Info]${Font_suffix}"
Error="${Red_font}[Error]${Font_suffix}"
@@ -17,229 +16,256 @@ echo -e "${Green_font}
${Font_suffix}"
check_root() {
[[ "$(id -u)" != "0" ]] && echo -e "${Error} must be root user !" && exit 1
[[ "$(id -u)" != "0" ]] && echo -e "${Error} must be root user !" && exit 1
}
checkNexttrace() {
echo -e "${Info} 正在检查Nexttrace..."
if curl -sL -O "https://github.com/xgadget-lab/nexttrace/raw/main/nt_install.sh" || curl -sL -O "https://github.com/xgadget-lab/nexttrace/raw/main/nt_install.sh"; then
bash nt_install.sh --auto > /dev/null
fi
}
ask_if()
{
local choice=""
while [ "$choice" != "y" ] && [ "$choice" != "n" ]
do
echo -e "${Info} $1"
read choice
done
[ $choice == y ] && return 0
return 1
echo -e "${Info} 正在检查Nexttrace...(若未安装NextTrace则开始安装)"
if curl -sL -O "https://github.com/xgadget-lab/nexttrace/raw/main/nt_install.sh" || curl -sL -O "https://github.com/xgadget-lab/nexttrace/raw/main/nt_install.sh"; then
bash nt_install.sh #--auto #>/dev/null
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"
;;
*)
red "unknown: $OSTYPE"
exit 1
;;
esac
}
#检查脚本更新
check_script_update()
{
check_script_update() {
if [[ ${osDistribution} == "darwin" ]]; then
[ "$(md5 <"${BASH_SOURCE[0]}")" == "$(curl -sL "https://github.com/xgadget-lab/nexttrace/raw/main/quicklytest.sh" | md5)" ] && return 1 || return 0
else
[ "$(md5sum "${BASH_SOURCE[0]}" | awk '{print $1}')" == "$(md5sum <(curl -sL "https://github.com/xgadget-lab/nexttrace/raw/main/quicklytest.sh") | awk '{print $1}')" ] && return 1 || return 0
fi
}
#更新脚本
update_script()
{
if curl -sL -o "${BASH_SOURCE[0]}" "https://github.com/xgadget-lab/nexttrace/raw/main/quicklytest.sh" || curl -sL -o "${BASH_SOURCE[0]}" "https://github.com/xgadget-lab/nexttrace/raw/main/quicklytest.sh"; then
echo -e "${Info} 脚本更新完成,正在重启脚本..."
exec bash ${BASH_SOURCE[0]}
else
echo -e "${Info} 更新脚本失败!"
exit 1
fi
update_script() {
if curl -sL -o "${BASH_SOURCE[0]}" "https://github.com/xgadget-lab/nexttrace/raw/main/quicklytest.sh" || curl -sL -o "${BASH_SOURCE[0]}" "https://github.com/xgadget-lab/nexttrace/raw/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} 脚本可升级"
ask_if "是否升级脚本?(y/n)" && update_script
else
echo -e "${Info} 脚本已经是最新版本"
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 -p "输入数字以选择:" node
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 -p "输入数字以选择:" node
done
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"
[[ "${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 -realtime"
# ##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"
echo -e "${Info} 结果是否制表?(制表模式为非实时显示)"
if ask_if "输入y/n以选择模式:" ; then
TRACECMD=${TRACECMD}" -rdns -table"
##Route-Path功能还未完善,临时替代:
[[ "${node}" == "2" ]] && TRACECMD=${TRACECMD}" -report"
##
else
TRACECMD=${TRACECMD}" -rdns -realtime"
##Route-Path功能还未完善,临时替代:
[[ "${node}" == "1" ]] && TRACECMD=${TRACECMD}" -report"
##
fi
#echo -e "${Info} 是否输出Route-Path?"
#ask_if "输入y/n以选择模式:" && TRACECMD=${TRACECMD}" -report"
}
test_single() {
echo -e "${Info} 请输入你要测试的目标 ip :"
read -p "输入 ip 地址:" ip
echo -e "${Info} 请输入你要测试的目标 ip :"
read -r -p "输入 ip 地址:" ip
while [[ -z "${ip}" ]]; do
echo -e "${Error} 无效输入"
echo -e "${Info} 请重新输入" && read -p "输入 ip 地址:" ip
done
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'
${TRACECMD} "${ip}" | grep -v -E 'NextTrace|XGadget-lab|Data\ Provider'
repeat_test_single
repeat_test_single
}
repeat_test_single() {
echo -e "${Info} 是否继续测试其他目标 ip ?"
if ask_if "输入y/n以选择:" ; then
test_single
else
echo -e "${Info} 退出脚本 ..." && exit 0
fi
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
set_alternative
result_alternative
}
select_alternative() {
echo -e "${Info} 选择需要测速的目标网络: \n1.中国电信\n2.中国联通\n3.中国移动\n4.教育网"
read -p "输入数字以选择:" ISP
echo -e "${Info} 选择需要测速的目标网络: \n1.中国电信\n2.中国联通\n3.中国移动\n4.教育网"
read -r -p "输入数字以选择:" ISP
while [[ ! "${ISP}" =~ ^[1-4]$ ]]; do
echo -e "${Error} 无效输入"
echo -e "${Info} 请重新选择" && read -p "输入数字以选择:" ISP
done
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
[[ "${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 -p "输入数字以选择:" node
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 -p "输入数字以选择:" node
done
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}" == "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 -p "输入数字以选择:" node
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 -p "输入数字以选择:" node
done
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}" == "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 -p "输入数字以选择:" node
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 -p "输入数字以选择:" node
done
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}" == "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
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
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 "输入y/n以选择:" ; then
test_alternative
else
echo -e "${Info} 退出脚本 ..." && exit 0
fi
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 '116.6.211.41' '广东东莞CN2'
result_all '101.95.110.149' '上海电信'
result_all '101.95.110.149' '上海电信'
result_all '112.85.231.129' '江苏徐州联通'
result_all '112.85.231.129' '江苏徐州联通'
result_all '120.199.239.1' '浙江杭州移动'
result_all '120.199.239.1' '浙江杭州移动'
result_all '211.68.69.240' '北京教育网'
result_all '211.68.69.240' '北京教育网'
echo -e "${Info} 四网路由快速测试 已完成 "
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} 完成 "
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
ask_update_script
checkNexttrace
check_mode
echo -e "${Info} 选择你要使用的功能: "
echo -e "1.选择一个节点进行测试\n2.四网路由快速测试\n3.手动输入 ip 进行测试"
read -p "输入数字以选择:" function
read -r -p "输入数字以选择:" function
while [[ ! "${function}" =~ ^[1-3]$ ]]; do
echo -e "${Error} 缺少或无效输入"
echo -e "${Info} 请重新选择" && read -p "输入数字以选择:" function
echo -e "${Error} 缺少或无效输入"
echo -e "${Info} 请重新选择" && read -r -p "输入数字以选择:" function
done
if [[ "${function}" == "1" ]]; then
test_alternative
test_alternative
elif [[ "${function}" == "2" ]]; then
test_all
test_all
else
test_single
test_single
fi