forked from wikihost-opensource/als
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testrace.sh
395 lines (344 loc) · 14.7 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
#!/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: 0.0.1
# Blog: https://vpsxb.net
#======================================
${Font_suffix}"
check_system(){
if [[ ! -z "`cat /etc/issue | grep -iE "debian"`" ]]; then
apt-get install traceroute mtr -y
elif [[ ! -z "`cat /etc/issue | grep -iE "ubuntu"`" ]]; then
apt-get install traceroute mtr -y
elif [[ ! -z "`cat /etc/redhat-release | grep -iE "CentOS"`" ]]; then
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(){
cd /usr/local/bin
}
install(){
[[ ! -f /usr/local/bin/nexttrace ]] && bash <(curl -Ls https://raw.githubusercontent.com/sjlleo/nexttrace/main/nt_install.sh)
[[ ! -f /usr/local/bin/nexttrace ]] && echo -e "${Error} download failed, please check!" && exit 1
}
test_single_tcp(){
echo -e "${Info} 请输入你要测试的目标 ip :"
read -p "输入 ip 地址:" ip
while [[ -z "${ip}" ]]
do
echo -e "${Error} 无效输入"
echo -e "${Info} 请重新输入" && read -p "输入 ip 地址:" ip
done
./nexttrace -T -q 1 -g cn ${ip}
repeat_test_single_tcp
}
repeat_test_single_tcp(){
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_tcp
[[ "${whether_repeat_single}" == "2" ]] && echo -e "${Info} 退出脚本 ..." && exit 0
}
test_alternative_tcp(){
select_alternative_tcp
set_alternative_tcp
result_alternative_tcp
}
select_alternative_tcp(){
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_tcp(){
[[ "${ISP}" == "1" ]] && node_1
[[ "${ISP}" == "2" ]] && node_2
[[ "${ISP}" == "3" ]] && node_3
[[ "${ISP}" == "4" ]] && node_4
}
node_1(){
echo -e "1.上海电信\n2.上海CN2\n3.厦门CN2\n4.杭州电信\n5.嘉兴电信\n6.广州电信(天翼云)\n7.北京电信" && read -p "输入数字以选择:" node
while [[ ! "${node}" =~ ^[1-7]$ ]]
do
echo -e "${Error} 无效输入"
echo -e "${Info} 请重新选择" && read -p "输入数字以选择:" node
done
[[ "${node}" == "1" ]] && ISP_name="上海电信" && ip=ipv4.sha-4134.endpoint.nxtrace.org
[[ "${node}" == "2" ]] && ISP_name="上海CN2" && ip=ipv4.sha-4809.endpoint.nxtrace.org
[[ "${node}" == "3" ]] && ISP_name="厦门CN2" && ip=117.28.254.129
[[ "${node}" == "4" ]] && ISP_name="杭州电信" && ip=ipv4.hgh-4134.endpoint.nxtrace.org
[[ "${node}" == "5" ]] && ISP_name="嘉兴电信" && ip=183.134.62.129
[[ "${node}" == "6" ]] && ISP_name="广州电信" && ip=ipv4.can-4134.endpoint.nxtrace.org
[[ "${node}" == "7" ]] && ISP_name="北京电信" && ip=ipv4.pek-4134.endpoint.nxtrace.org
}
node_2(){
echo -e "1.广州联通\n2.北京联通\n3.杭州联通\n4.安徽合肥联通\n5.嘉兴联通\n6.上海联通\n7.上海联通9929" && read -p "输入数字以选择:" node
while [[ ! "${node}" =~ ^[1-7]$ ]]
do
echo -e "${Error} 无效输入"
echo -e "${Info} 请重新选择" && read -p "输入数字以选择:" node
done
[[ "${node}" == "1" ]] && ISP_name="广州联通" && ip=ipv4.can-4837.endpoint.nxtrace.org
[[ "${node}" == "2" ]] && ISP_name="北京联通" && ip=ipv4.pek-4837.endpoint.nxtrace.org
[[ "${node}" == "3" ]] && ISP_name="杭州联通" && ip=ipv4.hgh-4837.endpoint.nxtrace.org
[[ "${node}" == "4" ]] && ISP_name="安徽合肥联通" && ip=112.122.10.26
[[ "${node}" == "5" ]] && ISP_name="嘉兴联通" && ip=60.12.95.255
[[ "${node}" == "6" ]] && ISP_name="上海联通" && ip=ipv4.sha-4837.endpoint.nxtrace.org
[[ "${node}" == "7" ]] && ISP_name="上海联通9929" && ip=ipv4.sha-9929.endpoint.nxtrace.org
}
node_3(){
echo -e "1.上海移动\n2.深圳移动\n3.北京移动\n4.嘉兴移动\n5.杭州移动" && read -p "输入数字以选择:" node
while [[ ! "${node}" =~ ^[1-5]$ ]]
do
echo -e "${Error} 无效输入"
echo -e "${Info} 请重新选择" && read -p "输入数字以选择:" node
done
[[ "${node}" == "1" ]] && ISP_name="上海移动" && ip=ipv4.sha-9808.endpoint.nxtrace.org
[[ "${node}" == "2" ]] && ISP_name="广州移动" && ip=ipv4.can-9808.endpoint.nxtrace.org
[[ "${node}" == "3" ]] && ISP_name="北京移动" && ip=ipv4.pek-9808.endpoint.nxtrace.org
[[ "${node}" == "4" ]] && ISP_name="嘉兴移动" && ip=223.95.245.102
[[ "${node}" == "5" ]] && ISP_name="杭州移动" && ip=ipv4.hgh-9808.endpoint.nxtrace.org
}
node_4(){
ISP_name="北京教育网" && ip=101.4.117.213
}
result_alternative_tcp(){
echo -e "${Info} 测试路由 到 ${ISP_name} 中 ..."
./nexttrace -T -q 1 -g cn ${ip}
echo -e "${Info} 测试路由 到 ${ISP_name} 完成 !"
repeat_test_alternative_tcp
}
repeat_test_alternative_tcp(){
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_tcp
[[ "${whether_repeat_alternative}" == "2" ]] && echo -e "${Info} 退出脚本 ..." && exit 0
}
test_all_tcp(){
result_all_tcp 'ipv4.sha-4134.endpoint.nxtrace.org' '上海电信'
result_all_tcp 'ipv4.sha-4809.endpoint.nxtrace.org' '上海CN2'
result_all_tcp 'ipv4.sha-4837.endpoint.nxtrace.org' '上海联通'
result_all_tcp 'ipv4.sha-9929.endpoint.nxtrace.org' '上海联通9929'
result_all_tcp 'ipv4.sha-9808.endpoint.nxtrace.org' '上海移动'
result_all_tcp 'ipv4.can-9808.endpoint.nxtrace.org' '广州移动'
result_all_tcp 'ipv4.hgh-4538.endpoint.nxtrace.org' '杭州教育网'
echo -e "${Info} 四网路由快速测试 已完成 !"
}
result_all_tcp(){
ISP_name=$2
echo -e "${Info} 测试路由 到 ${ISP_name} 中 ..."
./nexttrace -T -q 1 -g cn $1
echo -e "${Info} 测试路由 到 ${ISP_name} 完成 !"
}
test_all_tcp(){
result_all_tcp 'ipv4.sha-4134.endpoint.nxtrace.org' '上海电信'
result_all_tcp 'ipv4.sha-4809.endpoint.nxtrace.org' '上海CN2'
result_all_tcp 'ipv4.sha-4837.endpoint.nxtrace.org' '上海联通'
result_all_tcp 'ipv4.sha-9929.endpoint.nxtrace.org' '上海联通9929'
result_all_tcp 'ipv4.sha-9808.endpoint.nxtrace.org' '上海移动'
result_all_tcp 'ipv4.can-9808.endpoint.nxtrace.org' '广州移动'
result_all_tcp 'ipv4.hgh-4538.endpoint.nxtrace.org' '杭州教育网'
echo -e "${Info} 四网路由快速测试 已完成 !"
}
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
./nexttrace -q 1 -g cn ${ip}
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.厦门CN2\n4.杭州电信\n5.嘉兴电信\n6.广州电信\n7.北京电信" && read -p "输入数字以选择:" node
while [[ ! "${node}" =~ ^[1-7]$ ]]
do
echo -e "${Error} 无效输入"
echo -e "${Info} 请重新选择" && read -p "输入数字以选择:" node
done
[[ "${node}" == "1" ]] && ISP_name="上海电信" && ip=ipv4.sha-4134.endpoint.nxtrace.org
[[ "${node}" == "2" ]] && ISP_name="上海CN2" && ip=ipv4.sha-4809.endpoint.nxtrace.org
[[ "${node}" == "3" ]] && ISP_name="厦门CN2" && ip=117.28.254.129
[[ "${node}" == "4" ]] && ISP_name="杭州电信" && ip=ipv4.hgh-4134.endpoint.nxtrace.org
[[ "${node}" == "5" ]] && ISP_name="嘉兴电信" && ip=183.134.62.129
[[ "${node}" == "6" ]] && ISP_name="广州电信" && ip=ipv4.can-4134.endpoint.nxtrace.org
[[ "${node}" == "7" ]] && ISP_name="北京电信" && ip=ipv4.pek-4134.endpoint.nxtrace.org
}
node_2(){
echo -e "1.深圳联通\n2.北京联通\n3.杭州联通\n4.安徽合肥联通\n5.嘉兴联通\n6.上海联通\n7.上海联通9929" && read -p "输入数字以选择:" node
while [[ ! "${node}" =~ ^[1-7]$ ]]
do
echo -e "${Error} 无效输入"
echo -e "${Info} 请重新选择" && read -p "输入数字以选择:" node
done
[[ "${node}" == "1" ]] && ISP_name="广州联通" && ip=ipv4.can-4837.endpoint.nxtrace.org
[[ "${node}" == "2" ]] && ISP_name="北京联通" && ip=ipv4.pek-4837.endpoint.nxtrace.org
[[ "${node}" == "3" ]] && ISP_name="杭州联通" && ip=ipv4.hgh-4837.endpoint.nxtrace.org
[[ "${node}" == "4" ]] && ISP_name="安徽合肥联通" && ip=112.122.10.26
[[ "${node}" == "5" ]] && ISP_name="嘉兴联通" && ip=60.12.95.255
[[ "${node}" == "6" ]] && ISP_name="上海联通" && ip=ipv4.sha-4837.endpoint.nxtrace.org
[[ "${node}" == "7" ]] && ISP_name="上海联通9929" && ip=ipv4.sha-9929.endpoint.nxtrace.org
}
node_3(){
echo -e "1.上海移动\n2.广州移动\n3.北京移动\n4.广移V6\n5.杭州移动" && read -p "输入数字以选择:" node
while [[ ! "${node}" =~ ^[1-5]$ ]]
do
echo -e "${Error} 无效输入"
echo -e "${Info} 请重新选择" && read -p "输入数字以选择:" node
done
[[ "${node}" == "1" ]] && ISP_name="上海移动" && ip=ipv4.sha-9808.endpoint.nxtrace.org
[[ "${node}" == "2" ]] && ISP_name="广州移动" && ip=ipv4.can-9808.endpoint.nxtrace.org
[[ "${node}" == "3" ]] && ISP_name="北京移动" && ip=ipv4.pek-9808.endpoint.nxtrace.org
[[ "${node}" == "4" ]] && ISP_name="广移V6" && ip=ipv6.can-9808.endpoint.nxtrace.org
[[ "${node}" == "5" ]] && ISP_name="杭州移动" && ip=ipv4.hgh-9808.endpoint.nxtrace.org
}
node_4(){
ISP_name="北京教育网" && ip=101.4.117.213
}
result_alternative(){
echo -e "${Info} 测试路由 到 ${ISP_name} 中 ..."
./nexttrace -q 1 -g cn ${ip}
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 'ipv4.sha-4134.endpoint.nxtrace.org' '上海电信'
result_all 'ipv4.sha-4809.endpoint.nxtrace.org' '上海CN2'
result_all 'ipv4.sha-4837.endpoint.nxtrace.org' '上海联通'
result_all 'ipv4.sha-9929.endpoint.nxtrace.org' '上海联通9929'
result_all 'ipv4.sha-9808.endpoint.nxtrace.org' '上海移动'
result_all 'ipv4.can-9808.endpoint.nxtrace.org' '广州移动'
result_all 'ipv4.hgh-4538.endpoint.nxtrace.org' '杭州教育网'
echo -e "${Info} 四网路由快速测试 已完成 !"
}
result_all(){
ISP_name=$2
echo -e "${Info} 测试路由 到 ${ISP_name} 中 ..."
./nexttrace -q 1 -g cn $1
echo -e "${Info} 测试路由 到 ${ISP_name} 完成 !"
}
test_all(){
result_all 'ipv4.sha-4134.endpoint.nxtrace.org' '上海电信'
result_all 'ipv4.sha-4809.endpoint.nxtrace.org' '上海CN2'
result_all 'ipv4.sha-4837.endpoint.nxtrace.org' '上海联通'
result_all 'ipv4.sha-9929.endpoint.nxtrace.org' '上海联通9929'
result_all 'ipv4.sha-9808.endpoint.nxtrace.org' '上海移动'
result_all 'ipv4.can-9808.endpoint.nxtrace.org' '广州移动'
result_all 'ipv4.hgh-4538.endpoint.nxtrace.org' '杭州教育网'
echo -e "${Info} 四网路由快速测试 已完成 !"
}
test_allv6(){
result_all 'ipv6.sha-4134.endpoint.nxtrace.org' '上海电信'
# result_all '58.32.0.1' '上海CN2'
result_all 'ipv6.sha-4837.endpoint.nxtrace.org' '上海联通'
result_all 'ipv6.sha-9929.endpoint.nxtrace.org' '上海9929'
result_all 'ipv6.sha-9808.endpoint.nxtrace.org' '上海移动'
result_all 'ipv6.can-9808.endpoint.nxtrace.org' '广州移动'
result_all '2001:da8:8000:12d::2' '教育网'
echo -e "${Info} 路由快速测试 已完成 !"
}
#check_system
check_root
directory
install
cd /usr/local/bin
echo -e "${Info} 选择你要使用的功能: "
echo "--------------------------------"
echo -e "1.选择一个运营商进行测试(tcp)\n2.四网路由快速测试(tcp)\n3.手动输入ip进行测试(tcp)\n4.选择一个运营商进行测试(icmp)\n5.四网路由快速测试(icmp)\n6.手动输入ip进行测试(icmp)\n7.四网IPV6路由测试(icmp):"
echo "--------------------------------"
echo -e "广告位:"
echo -e "垃圾场加速器:"
echo -e "https://lajic.eu/index.php#/register?code=OAM8uBQl"
echo "--------------------------------"
read -p "输入数字以选择:" function
while [[ ! "${function}" =~ ^[1-7]$ ]]
do
echo -e "${Error} 缺少或无效输入"
echo -e "${Info} 请重新选择" && read -p "输入数字以选择:" function
done
if [[ "${function}" == "1" ]]; then
test_alternative_tcp
elif [[ "${function}" == "2" ]]; then
test_all_tcp
elif [[ "${function}" == "3" ]]; then
test_single_tcp
elif [[ "${function}" == "4" ]]; then
test_alternative
elif [[ "${function}" == "5" ]]; then
test_all
elif [[ "${function}" == "6" ]]; then
test_single
elif [[ "${function}" == "7" ]]; then
test_allv6
fi