forked from nanqinlang-script/testrace
-
Notifications
You must be signed in to change notification settings - Fork 8
/
testrace.sh
211 lines (180 loc) · 6.87 KB
/
testrace.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/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}"
echo -e "${Green_font}
#======================================
# Project: testrace
# Version: 1.2
# Author: hijk, based on nanqinlang
# website: https://hijk.pp.ua
#======================================
${Font_suffix}"
check_system(){
if [[ ! -z "`cat /etc/issue | grep -iE "debian"`" ]]; then
apt update
apt install -y unzip
apt-get install traceroute mtr -y
elif [[ ! -z "`cat /etc/issue | grep -iE "ubuntu"`" ]]; then
apt update
apt install -y unzip
apt-get install traceroute mtr -y
elif [[ ! -z "`cat /etc/redhat-release | grep -iE "CentOS"`" ]]; then
yum install -y unzip
yum install traceroute mtr -y
else
echo -e "${Error} system not support!" && exit 1
fi
}
check_root(){
[[ "`id -u`" != "0" ]] && echo -e "${Error} must be root user !" && exit 1
}
directory(){
[[ ! -d /home/testrace ]] && mkdir -p /home/testrace
cd /home/testrace
}
install(){
[[ ! -d /home/testrace/besttrace ]] && wget -O besttrace.zip https://cdn.ipip.net/17mon/besttrace4linux.zip && unzip besttrace.zip -d besttrace && rm besttrace.zip
[[ ! -d /home/testrace/besttrace ]] && echo -e "${Error} download failed, please check!" && exit 1
chmod -R +x /home/testrace
}
test_single(){
echo -e "${Info} 请输入你要测试的目标 ip :"
read -p "输入 ip 地址:" ip
while [[ -z "${ip}" ]]
do
echo -e "${Error} 无效输入"
echo -e "${Info} 请重新输入" && read -p "输入 ip 地址:" ip
done
./besttrace -q 1 ${ip} | tee -a -i /home/testrace/testrace.log 2>/dev/null
repeat_test_single
}
repeat_test_single(){
echo -e "${Info} 是否继续测试其他目标 ip ?"
echo -e "1.是\n2.否"
read -p "请选择:" whether_repeat_single
while [[ ! "${whether_repeat_single}" =~ ^[1-2]$ ]]
do
echo -e "${Error} 无效输入"
echo -e "${Info} 请重新输入" && read -p "请选择:" whether_repeat_single
done
[[ "${whether_repeat_single}" == "1" ]] && test_single
[[ "${whether_repeat_single}" == "2" ]] && echo -e "${Info} 退出脚本 ..." && exit 0
}
test_alternative(){
select_alternative
set_alternative
result_alternative
}
select_alternative(){
echo -e "${Info} 选择需要测速的目标网络: \n1.中国电信\n2.中国联通\n3.中国移动\n4.教育网"
read -p "输入数字以选择:" ISP
while [[ ! "${ISP}" =~ ^[1-4]$ ]]
do
echo -e "${Error} 无效输入"
echo -e "${Info} 请重新选择" && read -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.广州电信(天翼云)" && read -p "输入数字以选择:" node
while [[ ! "${node}" =~ ^[1-6]$ ]]
do
echo -e "${Error} 无效输入"
echo -e "${Info} 请重新选择" && read -p "输入数字以选择:" node
done
[[ "${node}" == "1" ]] && ISP_name="上海电信(天翼云)" && ip=101.227.255.45
[[ "${node}" == "2" ]] && ISP_name="厦门电信CN2" && ip=117.28.254.129
[[ "${node}" == "3" ]] && ISP_name="湖北襄阳电信" && ip=58.51.94.106
[[ "${node}" == "4" ]] && ISP_name="江西南昌电信" && ip=182.98.238.226
[[ "${node}" == "5" ]] && ISP_name="广东深圳电信" && ip=119.147.52.35
[[ "${node}" == "6" ]] && ISP_name="广州电信(天翼云)" && ip=14.215.116.1
}
node_2(){
echo -e "1.西藏拉萨联通\n2.重庆联通\n3.河南郑州联通\n4.安徽合肥联通\n5.江苏南京联通\n6.浙江杭州联通" && read -p "输入数字以选择:" node
while [[ ! "${node}" =~ ^[1-6]$ ]]
do
echo -e "${Error} 无效输入"
echo -e "${Info} 请重新选择" && read -p "输入数字以选择:" node
done
[[ "${node}" == "1" ]] && ISP_name="西藏拉萨联通" && ip=221.13.70.244
[[ "${node}" == "2" ]] && ISP_name="重庆联通" && ip=113.207.32.65
[[ "${node}" == "3" ]] && ISP_name="河南郑州联通" && ip=61.168.23.74
[[ "${node}" == "4" ]] && ISP_name="安徽合肥联通" && ip=112.122.10.26
[[ "${node}" == "5" ]] && ISP_name="江苏南京联通" && ip=58.240.53.78
[[ "${node}" == "6" ]] && ISP_name="浙江杭州联通" && ip=101.71.241.238
}
node_3(){
echo -e "1.上海移动\n2.四川成都移动\n3.安徽合肥移动\n4.浙江杭州移动" && read -p "输入数字以选择:" node
while [[ ! "${node}" =~ ^[1-4]$ ]]
do
echo -e "${Error} 无效输入"
echo -e "${Info} 请重新选择" && read -p "输入数字以选择:" node
done
[[ "${node}" == "1" ]] && ISP_name="上海移动" && ip=221.130.188.251
[[ "${node}" == "2" ]] && ISP_name="四川成都移动" && ip=183.221.247.9
[[ "${node}" == "3" ]] && ISP_name="安徽合肥移动" && ip=120.209.140.60
[[ "${node}" == "4" ]] && ISP_name="浙江杭州移动" && ip=112.17.0.106
}
node_4(){
ISP_name="北京教育网" && ip=202.205.6.30
}
result_alternative(){
echo -e "${Info} 测试路由 到 ${ISP_name} 中 ..."
./besttrace -q 1 ${ip} | tee -a -i /home/testrace/testrace.log 2>/dev/null
echo -e "${Info} 测试路由 到 ${ISP_name} 完成 !"
repeat_test_alternative
}
repeat_test_alternative(){
echo -e "${Info} 是否继续测试其他节点?"
echo -e "1.是\n2.否"
read -p "请选择:" whether_repeat_alternative
while [[ ! "${whether_repeat_alternative}" =~ ^[1-2]$ ]]
do
echo -e "${Error} 无效输入"
echo -e "${Info} 请重新输入" && read -p "请选择:" whether_repeat_alternative
done
[[ "${whether_repeat_alternative}" == "1" ]] && test_alternative
[[ "${whether_repeat_alternative}" == "2" ]] && echo -e "${Info} 退出脚本 ..." && exit 0
}
test_all(){
result_all '101.95.120.109' '上海电信'
result_all '117.28.254.129' '厦门电信CN2'
result_all '123.125.81.6' '北京联通'
result_all '221.130.33.52' '北京移动'
result_all '202.112.14.151' '成都教育网'
echo -e "${Info} 四网路由快速测试 已完成 !"
}
result_all(){
ISP_name=$2
echo -e "${Info} 测试路由 到 ${ISP_name} 中 ..."
./besttrace -q 1 $1
echo -e "${Info} 测试路由 到 ${ISP_name} 完成 !"
}
check_system
check_root
directory
install
cd besttrace
echo -e "${Info} 选择你要使用的功能: "
echo -e "1.选择一个节点进行测试\n2.四网路由快速测试\n3.手动输入 ip 进行测试"
read -p "输入数字以选择:" function
while [[ ! "${function}" =~ ^[1-3]$ ]]
do
echo -e "${Error} 缺少或无效输入"
echo -e "${Info} 请重新选择" && read -p "输入数字以选择:" function
done
if [[ "${function}" == "1" ]]; then
test_alternative
elif [[ "${function}" == "2" ]]; then
test_all | tee -a -i /home/testrace/testrace.log 2>/dev/null
else
test_single
fi