-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.sh
2238 lines (2132 loc) · 115 KB
/
bench.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
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
# #------------------------------------------------------------------#
# | LemonBench 服务器测试工具 LemonBench Server Test Utility |
# #------------------------------------------------------------------#
# | Written by iLemonrain <[email protected]> |
# | My Blog: https://ilemonrain.com |
# | Telegram: https://t.me/ilemonrain |
# | Telegram (For +86 User): https://t.me/ilemonrain_chatbot |
# | Telegram Channel: https://t.me/ilemonrain_channel |
# #------------------------------------------------------------------#
# | If you like this project, feel free to donate! |
# | 如果你喜欢这个项目, 欢迎投喂打赏! |
# | |
# | Donate Method 打赏方式: |
# | Alipay QR Code: http://t.cn/EA3pZNt |
# | 支付宝二维码:http://t.cn/EA3pZNt |
# | Wechat QR Code: http://t.cn/EA3p639 |
# | 微信二维码: http://t.cn/EA3p639 |
# #------------------------------------------------------------------#
#
# 使用方法 (任选其一):
# (1) wget -qO- https://raw.githubusercontent.com/kotori-bgt/soft/master/bench.sh | bash -s full
# (2) curl -fsSL https://raw.githubusercontent.com/kotori-bgt/soft/master/bench.sh | bash -s full
#
# === 全局定义 =====================================
# 全局参数定义
BuildTime="20190814 BetaVersion"
WorkDir="/tmp/.LemonBench"
UA_LemonBench="LemonBench/${BuildTime}"
UA_Browser="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36"
# 字体颜色定义
Font_Black="\033[30m"
Font_Red="\033[31m"
Font_Green="\033[32m"
Font_Yellow="\033[33m"
Font_Blue="\033[34m"
Font_Purple="\033[35m"
Font_SkyBlue="\033[36m"
Font_White="\033[37m"
Font_Suffix="\033[0m"
# 消息提示定义
Msg_Info="${Font_Blue}[Info] ${Font_Suffix}"
Msg_Warning="${Font_Yellow}[Warning] ${Font_Suffix}"
Msg_Debug="${Font_Yellow}[Debug] ${Font_Suffix}"
Msg_Error="${Font_Red}[Error] ${Font_Suffix}"
Msg_Success="${Font_Green}[Success] ${Font_Suffix}"
Msg_Fail="${Font_Red}[Failed] ${Font_Suffix}"
# =================================================
# === 全局模块 =====================================
# Trap终止信号捕获
trap "Global_TrapSigExit_Sig1" 1
trap "Global_TrapSigExit_Sig2" 2
trap "Global_TrapSigExit_Sig3" 3
trap "Global_TrapSigExit_Sig15" 15
# Trap终止信号1 - 处理
Global_TrapSigExit_Sig1() {
echo -e "\n\n${Msg_Error}接收到终止信号(SIGHUP), 正在退出 ...\n"
Global_TrapSigExit_Action
exit 1
}
# Trap终止信号2 - 处理 (Ctrl+C)
Global_TrapSigExit_Sig2() {
echo -e "\n\n${Msg_Error}接收到终止信号(SIGINT / Ctrl+C), 正在退出 ...\n"
Global_TrapSigExit_Action
exit 1
}
# Trap终止信号3 - 处理
Global_TrapSigExit_Sig3() {
echo -e "\n\n${Msg_Error}接收到终止信号(SIGQUIT), 正在退出 ...\n"
Global_TrapSigExit_Action
exit 1
}
# Trap终止信号15 - 处理 (进程被杀)
Global_TrapSigExit_Sig15() {
echo -e "\n\n${Msg_Error}接收到终止信号(SIGTERM), 正在退出 ...\n"
Global_TrapSigExit_Action
exit 1
}
# 简易JSON解析器 (Deprecated)
# PharseJSON() {
# # 使用方法: PharseJSON "要解析的原JSON文本" "要解析的键值"
# # Example: PharseJSON ""Value":"123456"" "Value" [返回结果: 123456]
# echo -n $1 | grep -oP '(?<='$2'":)[0-9A-Za-z]+'
# if [ "$?" = "1" ]; then
# echo -n $1 | grep -oP ''$2'[" :]+\K[^"]+'
# if [ "$?" = "1" ]; then
# echo -n "null"
# return 1
# fi
# fi
#}
# 新版JSON解析
PharseJSON() {
# 使用方法: PharseJSON "要解析的原JSON文本" "要解析的键值"
# Example: PharseJSON ""Value":"123456"" "Value" [返回结果: 123456]
echo -n $1 | jq -r .$2
}
# Ubuntu PasteBin 提交工具
# 感谢 @metowolf 提供思路
PasteBin_Upload() {
local uploadresult="$(curl -fsSL -X POST \
--url https://paste.ubuntu.com \
--output /dev/null \
--write-out "%{url_effective}\n" \
--data-urlencode "content@${PASTEBIN_CONTENT:-/dev/stdin}" \
--data "poster=${PASTEBIN_POSTER:-LemonBench}" \
--data "expiration=${PASTEBIN_EXPIRATION:-year}" \
--data "syntax=${PASTEBIN_SYNTAX:-text}")"
if [ "$?" = "0" ]; then
echo -e "${Msg_Success}云端测试报告生成完成!请注意及时保存!"
echo -e "${Msg_Info}报告地址:${uploadresult}"
else
echo -e "${Msg_Warning}云端测试报告生成失败, 但您仍然可以通过 $HOME/LemonBench.Result.txt 获取测试报告内容!"
fi
}
# 读取配置文件
ReadConfig() {
# 使用方法: ReadConfig <配置文件> <读取参数>
# Example: ReadConfig "/etc/config.cfg" "Parameter"
cat $1 | sed '/^'$2'=/!d;s/.*=//'
}
# 程序启动动作
Global_StartupInit_Action() {
Global_Startup_Header
echo -e "${Msg_Info}已启动测试模式:${Font_SkyBlue}${Global_TestModeTips}${Font_Suffix}"
# 清理残留, 为新一次的运行做好准备
echo -e "${Msg_Info}正在初始化环境, 请稍后 ..."
rm -rf ${WorkDir}
rm -rf /.tmp_LBench/
mkdir ${WorkDir}/
echo -e "${Msg_Info}正在检查必需环境 ..."
Check_Virtwhat
Check_JSONQuery
Check_Speedtest
Check_BestTrace
Check_Spoofer
Check_SysBench
echo -e "${Msg_Info}正在启动测试 ...\n\n"
clear
}
Global_Exit_Action() {
rm -rf ${WorkDir}/
}
# 捕获异常信号后的动作
Global_TrapSigExit_Action() {
rm -rf ${WorkDir}
rm -rf /.tmp_LBench/
}
# =================================================
# =============== -> 主程序开始 <- ===============
# =============== SystemInfo模块 部分 ===============
SystemInfo_GetHostname() {
LBench_Result_Hostname="$(hostname)"
}
SystemInfo_GetCPUInfo() {
mkdir -p ${WorkDir}/data >/dev/null 2>&1
cat /proc/cpuinfo >${WorkDir}/data/cpuinfo
local ReadCPUInfo="cat ${WorkDir}/data/cpuinfo"
LBench_Result_CPUModelName="$($ReadCPUInfo | awk -F ': ' '/model name/{print $2}' | sort -u)"
LBench_Result_CPUCacheSize="$($ReadCPUInfo | awk -F ': ' '/cache size/{print $2}' | sort -u)"
LBench_Result_CPUPhysicalNumber="$($ReadCPUInfo | awk -F ': ' '/physical id/{print $2}' | sort -u | wc -l)"
LBench_Result_CPUCoreNumber="$($ReadCPUInfo | awk -F ': ' '/cpu cores/{print $2}' | sort -u)"
LBench_Result_CPUThreadNumber="$($ReadCPUInfo | awk -F ': ' '/cores/{print $2}' | wc -l)"
LBench_Result_CPUProcessorNumber="$($ReadCPUInfo | awk -F ': ' '/processor/{print $2}' | wc -l)"
LBench_Result_CPUSiblingsNumber="$($ReadCPUInfo | awk -F ': ' '/siblings/{print $2}' | sort -u)"
LBench_Result_CPUTotalCoreNumber="$($ReadCPUInfo | awk -F ': ' '/physical id/&&/0/{print $2}' | wc -l)"
# 虚拟化能力检测
SystemInfo_GetVirtType
if [ "${Var_VirtType}" = "dedicated" ] || [ "${Var_VirtType}" = "wsl" ]; then
LBench_Result_CPUIsPhysical="1"
local VirtCheck="$(cat /proc/cpuinfo | grep -oE 'vmx|svm' | uniq)"
if [ "${VirtCheck}" != "" ]; then
LBench_Result_CPUVirtualization="1"
local VirtualizationType="$(lscpu | awk /Virtualization:/'{print $2}')"
LBench_Result_CPUVirtualizationType="${VirtualizationType}"
else
LBench_Result_CPUVirtualization="0"
fi
else
LBench_Result_CPUIsPhysical="0"
fi
}
SystemInfo_GetCPUStat() {
local CPUStat_Result="$(top -bn1 | grep Cpu)"
# 原始数据
LBench_Result_CPUStat_user="$(Function_ReadCPUStat "${CPUStat_Result}" "us")"
LBench_Result_CPUStat_system="$(Function_ReadCPUStat "${CPUStat_Result}" "sy")"
LBench_Result_CPUStat_nice="$(Function_ReadCPUStat "${CPUStat_Result}" "ni")"
LBench_Result_CPUStat_idle="$(Function_ReadCPUStat "${CPUStat_Result}" "id")"
LBench_Result_CPUStat_iowait="$(Function_ReadCPUStat "${CPUStat_Result}" "wa")"
LBench_Result_CPUStat_hardint="$(Function_ReadCPUStat "${CPUStat_Result}" "hi")"
LBench_Result_CPUStat_softint="$(Function_ReadCPUStat "${CPUStat_Result}" "si")"
LBench_Result_CPUStat_steal="$(Function_ReadCPUStat "${CPUStat_Result}" "st")"
# 加工后的数据
LBench_Result_CPUStat_UsedAll="$(echo ${LBench_Result_CPUStat_user} ${LBench_Result_CPUStat_system} ${LBench_Result_CPUStat_nice} | awk '{printf "%.1f\n",$1+$2+$3}')"
}
Function_ReadCPUStat() {
if [ "$1" == "" ]; then
echo -n "nil"
else
local result="$(echo $1 | grep -oE "[0-9]{1,2}.[0-9]{1} $2" | awk '{print $1}')"
echo $result
fi
}
SystemInfo_GetSystemBit() {
LBench_Result_SystemBit="$(uname -m)"
if [ "${LBench_Result_SystemBit}" = "unknown" ]; then
LBench_Result_SystemBit="$(arch)"
fi
local is64="$(uname -m | grep -o "64")"
if [ "${is64}" == "64" ]; then
LBench_Result_SystemBit_Short="64"
LBench_Result_SystemBit_Full="amd64"
else
LBench_Result_SystemBit_Short="32"
LBench_Result_SystemBit_Full="i386"
fi
}
SystemInfo_GetMemInfo() {
mkdir -p ${WorkDir}/data >/dev/null 2>&1
cat /proc/meminfo >${WorkDir}/data/meminfo
local ReadMemInfo="cat ${WorkDir}/data/meminfo"
# 获取总内存
LBench_Result_MemoryTotal_KB="$($ReadMemInfo | awk '/MemTotal/{print $2}')"
LBench_Result_MemoryTotal_MB="$(echo $LBench_Result_MemoryTotal_KB | awk '{printf "%.2f\n",$1/1024}')"
LBench_Result_MemoryTotal_GB="$(echo $LBench_Result_MemoryTotal_KB | awk '{printf "%.2f\n",$1/1048576}')"
# 获取可用内存
local MemFree="$($ReadMemInfo | awk '/MemFree/{print $2}')"
local Buffers="$($ReadMemInfo | awk '/Buffers/{print $2}')"
local Cached="$($ReadMemInfo | awk '/Cached/{print $2}')"
LBench_Result_MemoryFree_KB="$(echo $MemFree $Buffers $Cached | awk '{printf $1+$2+$3}')"
LBench_Result_MemoryFree_MB="$(echo $LBench_Result_MemoryFree_KB | awk '{printf "%.2f\n",$1/1024}')"
LBench_Result_MemoryFree_GB="$(echo $LBench_Result_MemoryFree_KB | awk '{printf "%.2f\n",$1/1048576}')"
# 获取已用内存
local MemUsed="$(echo $LBench_Result_MemoryTotal_KB $LBench_Result_MemoryFree_KB | awk '{printf $1-$2}')"
LBench_Result_MemoryUsed_KB="$MemUsed"
LBench_Result_MemoryUsed_MB="$(echo $LBench_Result_MemoryUsed_KB | awk '{printf "%.2f\n",$1/1024}')"
LBench_Result_MemoryUsed_GB="$(echo $LBench_Result_MemoryUsed_KB | awk '{printf "%.2f\n",$1/1048576}')"
# 获取Swap总量
LBench_Result_SwapTotal_KB="$($ReadMemInfo | awk '/SwapTotal/{print $2}')"
LBench_Result_SwapTotal_MB="$(echo $LBench_Result_SwapTotal_KB | awk '{printf "%.2f\n",$1/1024}')"
LBench_Result_SwapTotal_GB="$(echo $LBench_Result_SwapTotal_KB | awk '{printf "%.2f\n",$1/1048576}')"
# 获取可用Swap
LBench_Result_SwapFree_KB="$($ReadMemInfo | awk '/SwapFree/{print $2}')"
LBench_Result_SwapFree_MB="$(echo $LBench_Result_SwapFree_KB | awk '{printf "%.2f\n",$1/1024}')"
LBench_Result_SwapFree_GB="$(echo $LBench_Result_SwapFree_KB | awk '{printf "%.2f\n",$1/1048576}')"
# 获取已用Swap
local SwapUsed="$(echo $LBench_Result_SwapTotal_KB $LBench_Result_SwapFree_KB | awk '{printf $1-$2}')"
LBench_Result_SwapUsed_KB="$SwapUsed"
LBench_Result_SwapUsed_MB="$(echo $LBench_Result_SwapUsed_KB | awk '{printf "%.2f\n",$1/1024}')"
LBench_Result_SwapUsed_GB="$(echo $LBench_Result_SwapUsed_KB | awk '{printf "%.2f\n",$1/1048576}')"
}
SystemInfo_GetOSRelease() {
if [ -f "/etc/centos-release" ]; then # CentOS
Var_OSRelease="centos"
local Var_OSReleaseFullName="$(cat /etc/os-release | awk -F '[= "]' '/PRETTY_NAME/{print $3,$4}')"
if [ "$(rpm -qa | grep -o el6 | sort -u)" = "el6" ]; then
Var_CentOSELRepoVersion="6"
local Var_OSReleaseVersion="$(cat /etc/centos-release | awk '{print $3}')"
elif [ "$(rpm -qa | grep -o el7 | sort -u)" = "el7" ]; then
Var_CentOSELRepoVersion="7"
local Var_OSReleaseVersion="$(cat /etc/centos-release | awk '{print $4}')"
else
local Var_CentOSELRepoVersion="unknown"
local Var_OSReleaseVersion="<Unknown Release>"
fi
local Var_OSReleaseArch="$(arch)"
LBench_Result_OSReleaseFullName="$Var_OSReleaseFullName $Var_OSReleaseVersion ($Var_OSReleaseArch)"
elif [ -f "/etc/fedora-release" ]; then # Fedora
Var_OSRelease="fedora"
local Var_OSReleaseFullName="$(cat /etc/os-release | awk -F '[= "]' '/PRETTY_NAME/{print $3}')"
local Var_OSReleaseVersion="$(cat /etc/fedora-release | awk '{print $3,$4,$5,$6,$7}')"
local Var_OSReleaseArch="$(arch)"
LBench_Result_OSReleaseFullName="$Var_OSReleaseFullName $Var_OSReleaseVersion ($Var_OSReleaseArch)"
elif [ -f "/etc/lsb-release" ]; then # Ubuntu
Var_OSRelease="ubuntu"
local Var_OSReleaseFullName="$(cat /etc/os-release | awk -F '[= "]' '/NAME/{print $3}' | head -n1)"
local Var_OSReleaseVersion="$(cat /etc/os-release | awk -F '[= "]' '/VERSION/{print $3,$4,$5,$6,$7}' | head -n1)"
local Var_OSReleaseArch="$(arch)"
LBench_Result_OSReleaseFullName="$Var_OSReleaseFullName $Var_OSReleaseVersion ($Var_OSReleaseArch)"
Var_OSReleaseVersion_Short="$(cat /etc/lsb-release | awk -F '[= "]' '/DISTRIB_RELEASE/{print $2}')"
elif [ -f "/etc/debian_version" ]; then # Debian
Var_OSRelease="debian"
local Var_OSReleaseFullName="$(cat /etc/os-release | awk -F '[= "]' '/PRETTY_NAME/{print $3,$4}')"
local Var_OSReleaseVersion="$(cat /etc/debian_version | awk '{print $1}')"
local Var_OSReleaseVersionShort="$(cat /etc/debian_version | awk '{printf "%d\n",$1}')"
if [ "${Var_OSReleaseVersionShort}" = "7" ]; then
Var_OSReleaseVersion_Short="7"
Var_OSReleaseVersion_Codename="wheezy"
local Var_OSReleaseFullName="${Var_OSReleaseFullName} \"Wheezy\""
elif [ "${Var_OSReleaseVersionShort}" = "8" ]; then
Var_OSReleaseVersion_Short="8"
Var_OSReleaseVersion_Codename="jessie"
local Var_OSReleaseFullName="${Var_OSReleaseFullName} \"Jessie\""
elif [ "${Var_OSReleaseVersionShort}" = "9" ]; then
Var_OSReleaseVersion_Short="9"
Var_OSReleaseVersion_Codename="stretch"
local Var_OSReleaseFullName="${Var_OSReleaseFullName} \"Stretch\""
elif [ "${Var_OSReleaseVersionShort}" = "10" ]; then
Var_OSReleaseVersion_Short="10"
Var_OSReleaseVersion_Codename="buster"
local Var_OSReleaseFullName="${Var_OSReleaseFullName} \"Buster\""
else
Var_OSReleaseVersion_Short="sid"
Var_OSReleaseVersion_Codename="sid"
local Var_OSReleaseFullName="${Var_OSReleaseFullName} \"Sid (Testing)\""
fi
local Var_OSReleaseArch="$(arch)"
LBench_Result_OSReleaseFullName="$Var_OSReleaseFullName $Var_OSReleaseVersion ($Var_OSReleaseArch)"
elif [ -f "/etc/alpine-release" ]; then # Alpine Linux
Var_OSRelease="alpinelinux"
local Var_OSReleaseFullName="$(cat /etc/os-release | awk -F '[= "]' '/NAME/{print $3,$4}' | head -n1)"
local Var_OSReleaseVersion="$(cat /etc/alpine-release | awk '{print $1}')"
local Var_OSReleaseArch="$(arch)"
LBench_Result_OSReleaseFullName="$Var_OSReleaseFullName $Var_OSReleaseVersion ($Var_OSReleaseArch)"
else
Var_OSRelease="unknown" # 未知系统分支
LBench_Result_OSReleaseFullName="[Error: 未知系统分支 !]"
fi
}
SystemInfo_GetVirtType() {
if [ ! -f "/usr/sbin/virt-what" ]; then
Var_VirtType="Unknown"
LBench_Result_VirtType="[Error: 未安装virt-what !]"
elif [ -f "/.dockerenv" ]; then # 处理Docker虚拟化
Var_VirtType="docker"
LBench_Result_VirtType="Docker"
elif [ -c "/dev/lxss" ]; then # 处理WSL虚拟化
Var_VirtType="wsl"
LBench_Result_VirtType="Windows Subsystem for Linux (WSL)"
else # 正常判断流程
Var_VirtType="$(virt-what | xargs)"
local Var_VirtTypeCount="$(echo $Var_VirtTypeCount | wc -l)"
if [ "${Var_VirtTypeCount}" -gt "1" ]; then # 处理嵌套虚拟化
LBench_Result_VirtType="echo ${Var_VirtType}"
Var_VirtType="$(echo ${Var_VirtType} | head -n1)" # 使用检测到的第一种虚拟化继续做判断
elif [ "${Var_VirtTypeCount}" -eq "1" ] && [ "${Var_VirtType}" != "" ]; then # 只有一种虚拟化
LBench_Result_VirtType="${Var_VirtType}"
else
local Var_BIOSVendor="$(dmidecode -s bios-vendor)"
if [ "${Var_BIOSVendor}" = "SeaBIOS" ]; then
Var_VirtType="Unknown"
LBench_Result_VirtType="Unknown with SeaBIOS BIOS"
else
Var_VirtType="dedicated"
LBench_Result_VirtType="Dedicated with ${Var_BIOSVendor} BIOS"
fi
fi
fi
}
SystemInfo_GetLoadAverage() {
local Var_LoadAverage="$(cat /proc/loadavg)"
LBench_Result_LoadAverage_1min="$(echo ${Var_LoadAverage} | awk '{print $1}')"
LBench_Result_LoadAverage_5min="$(echo ${Var_LoadAverage} | awk '{print $2}')"
LBench_Result_LoadAverage_15min="$(echo ${Var_LoadAverage} | awk '{print $3}')"
}
SystemInfo_GetDiskStat() {
LBench_Result_DiskRootPath="$(df -x tmpfs / | awk "NR>1" | sed ":a;N;s/\\n//g;ta" | awk '{print $1}')"
local Var_DiskTotalSpace_KB="$(df -x tmpfs / | grep -oE "[0-9]{4,}" | awk 'NR==1 {print $1}')"
LBench_Result_DiskTotal_KB="${Var_DiskTotalSpace_KB}"
LBench_Result_DiskTotal_MB="$(echo ${Var_DiskTotalSpace_KB} | awk '{printf "%.2f\n",$1/1000}')"
LBench_Result_DiskTotal_GB="$(echo ${Var_DiskTotalSpace_KB} | awk '{printf "%.2f\n",$1/1000000}')"
LBench_Result_DiskTotal_TB="$(echo ${Var_DiskTotalSpace_KB} | awk '{printf "%.2f\n",$1/1000000000}')"
local Var_DiskUsedSpace_KB="$(df -x tmpfs / | grep -oE "[0-9]{4,}" | awk 'NR==2 {print $1}')"
LBench_Result_DiskUsed_KB="${Var_DiskUsedSpace_KB}"
LBench_Result_DiskUsed_MB="$(echo ${LBench_Result_DiskUsed_KB} | awk '{printf "%.2f\n",$1/1000}')"
LBench_Result_DiskUsed_GB="$(echo ${LBench_Result_DiskUsed_KB} | awk '{printf "%.2f\n",$1/1000000}')"
LBench_Result_DiskUsed_TB="$(echo ${LBench_Result_DiskUsed_KB} | awk '{printf "%.2f\n",$1/1000000000}')"
local Var_DiskFreeSpace_KB="$(df -x tmpfs / | grep -oE "[0-9]{4,}" | awk 'NR==3 {print $1}')"
LBench_Result_DiskFree_KB="${Var_DiskFreeSpace_KB}"
LBench_Result_DiskFree_MB="$(echo ${LBench_Result_DiskFree_KB} | awk '{printf "%.2f\n",$1/1000}')"
LBench_Result_DiskFree_GB="$(echo ${LBench_Result_DiskFree_KB} | awk '{printf "%.2f\n",$1/1000000}')"
LBench_Result_DiskFree_TB="$(echo ${LBench_Result_DiskFree_KB} | awk '{printf "%.2f\n",$1/1000000000}')"
}
SystemInfo_GetNetworkInfo() {
LBench_Result_LocalIP_IPV4="$(curl --connect-timeout 5 -fsSL4 http://api-ipv4.ip.sb)"
LBench_Result_LocalIP_IPV6="$(curl --connect-timeout 5 -fsSL6 http://api-ipv6.ip.sb)"
# 判断三种网络情况:
# - IPV4 Only:只有IPV4
# - IPV6 Only:只有IPV6
# - DualStack:双栈 (IPV4+IPV6)
#
# 判断IPV4 Only
if [ "${LBench_Result_LocalIP_IPV4}" != "" ] && [ "${LBench_Result_LocalIP_IPV6}" = "" ]; then
LBench_Result_NetworkStat="ipv4only"
local IPAPI_Result_IPV4="$(curl -fsL4 --connect-timeout 5 https://api-ipv4.ip.sb/geoip/)"
# 判断IPV6 Only
elif [ "${LBench_Result_LocalIP_IPV4}" = "" ] && [ "${LBench_Result_LocalIP_IPV6}" != "" ]; then
LBench_Result_NetworkStat="ipv6only"
local IPAPI_Result_IPV6="$(curl -fsL6 --connect-timeout 5 https://api-ipv6.ip.sb/geoip)"
# 判断双栈
elif [ "${LBench_Result_LocalIP_IPV4}" != "" ] && [ "${LBench_Result_LocalIP_IPV6}" != "" ]; then
LBench_Result_NetworkStat="dualstack"
local IPAPI_Result_IPV4="$(curl -fsL4 --connect-timeout 5 https://api-ipv4.ip.sb/geoip/)"
local IPAPI_Result_IPV6="$(curl -fsL6 --connect-timeout 5 https://api-ipv6.ip.sb/geoip/)"
# 返回未知值
else
LBench_Result_NetworkStat="unknown"
fi
# 提取IPV4信息
if [ "${IPAPI_Result_IPV4}" != "" ]; then
IPAPI_IPV4_IP="$(PharseJSON "${IPAPI_Result_IPV4}" "ip")"
IPAPI_IPV4_city="$(PharseJSON "${IPAPI_Result_IPV4}" "city")"
IPAPI_IPV4_region="$(PharseJSON "${IPAPI_Result_IPV4}" "region")"
IPAPI_IPV4_country="$(PharseJSON "${IPAPI_Result_IPV4}" "country")"
IPAPI_IPV4_country_code="$(PharseJSON "${IPAPI_Result_IPV4}" "country_code")"
IPAPI_IPV4_asn="$(PharseJSON "${IPAPI_Result_IPV4}" "asn")"
IPAPI_IPV4_organization="$(PharseJSON "${IPAPI_Result_IPV4}" "organization")"
fi
if [ "${IPAPI_Result_IPV6}" != "" ]; then
IPAPI_IPV6_ip="$(PharseJSON "${IPAPI_Result_IPV6}" "ip")"
IPAPI_IPV6_city="$(PharseJSON "${IPAPI_Result_IPV6}" "city")"
IPAPI_IPV6_region="$(PharseJSON "${IPAPI_Result_IPV6}" "region")"
IPAPI_IPV6_country="$(PharseJSON "${IPAPI_Result_IPV6}" "country")"
IPAPI_IPV6_country_code="$(PharseJSON "${IPAPI_Result_IPV6}" "country_code")"
IPAPI_IPV6_asn="$(PharseJSON "${IPAPI_Result_IPV6}" "asn")"
IPAPI_IPV6_organization="$(PharseJSON "${IPAPI_Result_IPV6}" "organization")"
fi
}
Function_GetSystemInfo() {
clear
echo -e "${Msg_Info}LemonBench Server Test Toolkit Build ${BuildTime}"
echo -e "${Msg_Info}SystemInfo - 正在获取系统信息 ..."
Check_Virtwhat
echo -e "${Msg_Info}正在获取CPU信息 ..."
SystemInfo_GetCPUInfo
SystemInfo_GetLoadAverage
SystemInfo_GetSystemBit
SystemInfo_GetCPUStat
echo -e "${Msg_Info}正在获取内存信息 ..."
SystemInfo_GetMemInfo
echo -e "${Msg_Info}正在获取虚拟化类型信息 ..."
SystemInfo_GetVirtType
echo -e "${Msg_Info}正在获取系统版本信息 ..."
SystemInfo_GetOSRelease
echo -e "${Msg_Info}正在获取磁盘信息 ..."
SystemInfo_GetDiskStat
echo -e "${Msg_Info}正在获取网络信息 ..."
SystemInfo_GetNetworkInfo
clear
}
Function_ShowSystemInfo() {
echo -e "\n ${Font_Yellow}-> 系统信息${Font_Suffix}\n"
if [ "${Var_OSReleaseVersion_Codename}" != "" ]; then
echo -e " ${Font_Yellow}系统名称:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_OSReleaseFullName}${Font_Suffix}"
else
echo -e " ${Font_Yellow}系统名称:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_OSReleaseFullName}${Font_Suffix}"
fi
echo -e " ${Font_Yellow}CPU型号:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_CPUModelName}${Font_Suffix}"
echo -e " ${Font_Yellow}CPU缓存大小:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_CPUCacheSize}${Font_Suffix}"
# CPU数量 分支判断
if [ "${LBench_Result_CPUIsPhysical}" = "1" ]; then
# 如果只存在1个物理CPU (单路物理服务器)
if [ "${LBench_Result_CPUPhysicalNumber}" -eq "1" ]; then
echo -e " ${Font_Yellow}CPU数量:${Font_Suffix}\t\t${LBench_Result_CPUPhysicalNumber} ${Font_SkyBlue}物理CPU${Font_Suffix}, ${LBench_Result_CPUCoreNumber} ${Font_SkyBlue}核心${Font_Suffix}, ${LBench_Result_CPUThreadNumber} ${Font_SkyBlue}线程${Font_Suffix}"
# 存在多个CPU, 继续深入分析检测 (多路物理服务器)
else
echo -e " ${Font_Yellow}CPU数量:${Font_Suffix}\t\t${LBench_Result_CPUPhysicalNumber} ${Font_SkyBlue}物理CPU${Font_Suffix}, ${LBench_Result_CPUCoreNumber} ${Font_SkyBlue}核心/CPU${Font_Suffix}, ${LBench_Result_CPUSiblingsNumber} ${Font_SkyBlue}线程/CPU${Font_Suffix} (总共 ${Font_SkyBlue}${LBench_Result_CPUTotalCoreNumber}${Font_Suffix} 核心, ${Font_SkyBlue}${LBench_Result_CPUProcessorNumber}${Font_Suffix} 线程)"
fi
if [ "${LBench_Result_CPUVirtualization}" = "1" ]; then
echo -e " ${Font_Yellow}虚拟化已就绪:${Font_Suffix}\t\t${Font_SkyBlue}是${Font_Suffix} ${Font_SkyBlue}(基于${Font_Suffix} ${LBench_Result_CPUVirtualizationType}${Font_SkyBlue})${Font_Suffix}"
else
echo -e " ${Font_Yellow}虚拟化已就绪:${Font_Suffix}\t\t${Font_SkyRed}否${Font_Suffix}"
fi
elif [ "${Var_VirtType}" = "openvz" ]; then
echo -e " ${Font_Yellow}CPU数量:${Font_Suffix}\t\t${LBench_Result_CPUThreadNumber} ${Font_SkyBlue}vCPU${Font_Suffix} (${LBench_Result_CPUCoreNumber} ${Font_SkyBlue}宿主机核心${Font_Suffix})"
else
echo -e " ${Font_Yellow}CPU数量:${Font_Suffix}\t\t${LBench_Result_CPUThreadNumber} ${Font_SkyBlue}vCPU${Font_Suffix}"
fi
echo -e " ${Font_Yellow}虚拟化类型:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_VirtType}${Font_Suffix}"
# 内存使用率 分支判断
if [ "${LBench_Result_MemoryUsed_KB}" -lt "1024" ] && [ "${LBench_Result_MemoryTotal_KB}" -lt "1048576" ]; then
LBench_Result_Memory="${LBench_Result_MemoryUsed_KB} KB / ${LBench_Result_MemoryTotal_MB} MB"
echo -e " ${Font_Yellow}内存使用率:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_MemoryUsed_MB} KB${Font_Suffix} / ${Font_SkyBlue}${LBench_Result_MemoryTotal_MB} MB${Font_Suffix}"
elif [ "${LBench_Result_MemoryUsed_KB}" -lt "1048576" ] && [ "${LBench_Result_MemoryTotal_KB}" -lt "1048576" ]; then
LBench_Result_Memory="${LBench_Result_MemoryUsed_MB} MB / ${LBench_Result_MemoryTotal_MB} MB"
echo -e " ${Font_Yellow}内存使用率:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_MemoryUsed_MB} MB${Font_Suffix} / ${Font_SkyBlue}${LBench_Result_MemoryTotal_MB} MB${Font_Suffix}"
elif [ "${LBench_Result_MemoryUsed_KB}" -lt "1048576" ] && [ "${LBench_Result_MemoryTotal_KB}" -lt "1073741824" ]; then
LBench_Result_Memory="${LBench_Result_MemoryUsed_MB} MB / ${LBench_Result_MemoryTotal_GB} GB"
echo -e " ${Font_Yellow}内存使用率:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_MemoryUsed_MB} MB${Font_Suffix} / ${Font_SkyBlue}${LBench_Result_MemoryTotal_GB} GB${Font_Suffix}"
else
LBench_Result_Memory="${LBench_Result_MemoryUsed_GB} GB / ${LBench_Result_MemoryTotal_GB} GB"
echo -e " ${Font_Yellow}内存使用率:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_MemoryUsed_GB} GB${Font_Suffix} / ${Font_SkyBlue}${LBench_Result_MemoryTotal_GB} GB${Font_Suffix}"
fi
# Swap使用率 分支判断
if [ "${LBench_Result_SwapTotal_KB}" -eq "0" ]; then
LBench_Result_Swap="[无Swap分区/文件]"
echo -e " ${Font_Yellow}Swap使用率:${Font_Suffix}\t\t${Font_SkyBlue}[无Swap分区/文件]${Font_Suffix}"
elif [ "${LBench_Result_SwapUsed_KB}" -lt "1024" ] && [ "${LBench_Result_SwapTotal_KB}" -lt "1048576" ]; then
LBench_Result_Swap="${LBench_Result_SwapUsed_KB} KB / ${LBench_Result_SwapTotal_MB} MB"
echo -e " ${Font_Yellow}Swap使用率:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_SwapUsed_KB} KB${Font_Suffix} / ${Font_SkyBlue}${LBench_Result_SwapTotal_MB} MB${Font_Suffix}"
elif [ "${LBench_Result_SwapUsed_KB}" -lt "1024" ] && [ "${LBench_Result_SwapTotal_KB}" -lt "1073741824" ]; then
LBench_Result_Swap="${LBench_Result_SwapUsed_KB} KB / ${LBench_Result_SwapTotal_GB} GB"
echo -e " ${Font_Yellow}Swap使用率:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_SwapUsed_KB} KB${Font_Suffix} / ${Font_SkyBlue}${LBench_Result_SwapTotal_GB} GB${Font_Suffix}"
elif [ "${LBench_Result_SwapUsed_KB}" -lt "1048576" ] && [ "${LBench_Result_SwapTotal_KB}" -lt "1048576" ]; then
LBench_Result_Swap="${LBench_Result_SwapUsed_MB} MB / ${LBench_Result_SwapTotal_MB} MB"
echo -e " ${Font_Yellow}Swap使用率:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_SwapUsed_MB} MB${Font_Suffix} / ${Font_SkyBlue}${LBench_Result_SwapTotal_MB} MB${Font_Suffix}"
elif [ "${LBench_Result_SwapUsed_KB}" -lt "1048576" ] && [ "${LBench_Result_SwapTotal_KB}" -lt "1073741824" ]; then
LBench_Result_Swap="${LBench_Result_SwapUsed_MB} MB / ${LBench_Result_SwapTotal_GB} GB"
echo -e " ${Font_Yellow}Swap使用率:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_SwapUsed_MB} MB${Font_Suffix} / ${Font_SkyBlue}${LBench_Result_SwapTotal_GB} GB${Font_Suffix}"
else
LBench_Result_Swap="${LBench_Result_SwapUsed_GB} GB / ${LBench_Result_SwapTotal_GB} GB"
echo -e " ${Font_Yellow}Swap使用率:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_SwapUsed_GB} GB${Font_Suffix} / ${Font_SkyBlue}${LBench_Result_SwapTotal_GB} GB${Font_Suffix}"
fi
# 启动磁盘
echo -e "${Font_Yellow} 引导设备:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_DiskRootPath}${Font_Suffix}"
# 磁盘使用率 分支判断
if [ "${LBench_Result_DiskUsed_KB}" -lt "1000000" ]; then
LBench_Result_Disk="${LBench_Result_DiskUsed_MB} MB / ${LBench_Result_DiskTotal_MB} MB"
echo -e " ${Font_Yellow}磁盘使用率:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_DiskUsed_MB} MB${Font_Suffix} / ${Font_SkyBlue}${LBench_Result_DiskTotal_MB} MB${Font_Suffix}"
elif [ "${LBench_Result_DiskUsed_KB}" -lt "1000000" ] && [ "${LBench_Result_DiskTotal_KB}" -lt "1000000000" ]; then
LBench_Result_Disk="${LBench_Result_DiskUsed_MB} MB / ${LBench_Result_DiskTotal_GB} GB"
echo -e " ${Font_Yellow}磁盘使用率:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_DiskUsed_MB} MB${Font_Suffix} / ${Font_SkyBlue}${LBench_Result_DiskTotal_GB} GB${Font_Suffix}"
elif [ "${LBench_Result_DiskUsed_KB}" -lt "1000000000" ] && [ "${LBench_Result_DiskTotal_KB}" -lt "1000000000" ]; then
LBench_Result_Disk="${LBench_Result_DiskUsed_GB} GB / ${LBench_Result_DiskTotal_GB} GB"
echo -e " ${Font_Yellow}磁盘使用率:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_DiskUsed_GB} GB${Font_Suffix} / ${Font_SkyBlue}${LBench_Result_DiskTotal_GB} GB${Font_Suffix}"
elif [ "${LBench_Result_DiskUsed_KB}" -lt "1000000000" ] && [ "${LBench_Result_DiskTotal_KB}" -ge "1000000000" ]; then
LBench_Result_Disk="${LBench_Result_DiskUsed_GB} GB / ${LBench_Result_DiskTotal_TB} TB"
echo -e " ${Font_Yellow}磁盘使用率:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_DiskUsed_GB} GB${Font_Suffix} / ${Font_SkyBlue}${LBench_Result_DiskTotal_TB} TB${Font_Suffix}"
else
LBench_Result_Disk="${LBench_Result_DiskUsed_TB} TB / ${LBench_Result_DiskTotal_TB} TB"
echo -e " ${Font_Yellow}磁盘使用率:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_DiskUsed_TB} TB${Font_Suffix} / ${Font_SkyBlue}${LBench_Result_DiskTotal_TB} TB${Font_Suffix}"
fi
# CPU状态
echo -e " ${Font_Yellow}CPU负载:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_CPUStat_UsedAll}% used${Font_Suffix}, ${Font_SkyBlue}${LBench_Result_CPUStat_iowait}% iowait${Font_Suffix}, ${Font_SkyBlue}${LBench_Result_CPUStat_steal}% steal${Font_Suffix}"
# 系统负载
echo -e " ${Font_Yellow}系统负载(1/5/15min):${Font_Suffix}\t${Font_SkyBlue}${LBench_Result_LoadAverage_1min} ${LBench_Result_LoadAverage_5min} ${LBench_Result_LoadAverage_15min} ${Font_Suffix}"
# 执行完成, 标记FLAG
LBench_Flag_FinishSystemInfo="1"
}
Function_ShowNetworkInfo() {
echo -e "\n ${Font_Yellow}-> 网络信息${Font_Suffix}\n"
if [ "${LBench_Result_NetworkStat}" = "ipv4only" ] || [ "${LBench_Result_NetworkStat}" = "dualstack" ]; then
echo -e " ${Font_Yellow}IPV4 - 本机IP:${Font_Suffix}\t\t${Font_SkyBlue}[${IPAPI_IPV4_country_code}] ${IPAPI_IPV4_IP}${Font_Suffix}"
echo -e " ${Font_Yellow}IPV4 - ASN信息:${Font_Suffix}\t${Font_SkyBlue}AS${IPAPI_IPV4_asn} (${IPAPI_IPV4_organization})${Font_Suffix}"
echo -e " ${Font_Yellow}IPV4 - 归属地:${Font_Suffix}\t\t${Font_SkyBlue}${IPAPI_IPV4_country}, ${IPAPI_IPV4_region}${Font_Suffix}"
fi
if [ "${LBench_Result_NetworkStat}" = "ipv6only" ] || [ "${LBench_Result_NetworkStat}" = "dualstack" ]; then
echo -e " ${Font_Yellow}IPV6 - 本机IP:${Font_Suffix}\t\t${Font_SkyBlue}[${IPAPI_IPV6_country_code}] ${IPAPI_IPV6_ip}${Font_Suffix}"
echo -e " ${Font_Yellow}IPV6 - ASN信息:${Font_Suffix}\t${Font_SkyBlue}AS${IPAPI_IPV6_asn} (${IPAPI_IPV6_organization})${Font_Suffix}"
echo -e " ${Font_Yellow}IPV6 - 归属地:${Font_Suffix}\t\t${Font_SkyBlue}${IPAPI_IPV6_country}, ${IPAPI_IPV6_region}${Font_Suffix}"
fi
# 执行完成, 标记FLAG
LBench_Flag_FinishNetworkInfo="1"
}
# =============== 测试启动与结束动作 ===============
Function_BenchStart() {
clear
LBench_Result_BenchStartTime="$(date +"%Y-%m-%d %H:%M:%S")"
echo -e "${Font_SkyBlue}LemonBench${Font_Suffix} ${Font_Yellow}Server Test Tookit${Font_Suffix} ${BuildTime} ${Font_SkyBlue}(C)iLemonrain. All Rights Reserved.${Font_Suffix}"
echo -e "=========================================================================================="
echo -e " "
echo -e " ${Msg_Info}${Font_Yellow}测试开始时间:${Font_Suffix} ${Font_SkyBlue}${LBench_Result_BenchStartTime}${Font_Suffix}"
echo -e " ${Msg_Info}${Font_Yellow}测试模式:${Font_Suffix} ${Font_SkyBlue}${Global_TestModeTips}${Font_Suffix}"
echo -e " "
}
Function_BenchFinish() {
# 清理临时文件
LBench_Result_BenchFinishTime="$(date +"%Y-%m-%d %H:%M:%S")"
echo -e ""
echo -e "=========================================================================================="
echo -e " "
echo -e " ${Msg_Info}${Font_Yellow}测试结束时间:${Font_Suffix} ${Font_SkyBlue}${LBench_Result_BenchFinishTime}${Font_Suffix}"
echo -e " "
}
# =============== 流媒体解锁测试 部分 ===============
# 流媒体解锁测试
Function_MediaUnlockTest() {
echo -e " "
echo -e "${Font_Yellow} -> 流媒体解锁测试 ${Font_Suffix}"
echo -e " "
Function_MediaUnlockTest_HBONow
Function_MediaUnlockTest_BahamutAnime
Function_MediaUnlockTest_BilibiliHKMCTW
Function_MediaUnlockTest_BilibiliTW
LBench_Flag_FinishMediaUnlockTest="1"
}
# 流媒体解锁测试-HBO Now
Function_MediaUnlockTest_HBONow() {
echo -n -e " HBONow:\c"
# 尝试获取成功的结果
local result="$(curl --user-agent "${UA_Browser}" -4 -fsSL --max-time 30 --write-out "%{url_effective}\n" --output /dev/null https://play.hbonow.com/)"
if [ "$?" = "0" ]; then
# 下载页面成功,开始解析跳转
if [ "${result}" = "https://play.hbonow.com" ] || [ "${result}" = "https://play.hbonow.com/" ]; then
echo -n -e "\r HBO Now:\t\t${Font_Green}是${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_HBONow="是"
elif [ "${result}" = "http://hbogeo.cust.footprint.net/hbonow/geo.html" ]; then
echo -n -e "\r HBO Now:\t\t${Font_Red}否${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_HBONow="否"
else
echo -n -e "\r HBO Now:\t${Font_Yellow}失败-解析失败${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_HBONow="测试失败 (解析失败)"
fi
else
# 下载页面失败,返回错误代码
echo -e "\r HBO Now:\t\t${Font_Yellow}失败-网络连接异常${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_HBONow="测试失败 (网络连接异常)"
fi
}
# 流媒体解锁测试-动画疯
Function_MediaUnlockTest_BahamutAnime() {
echo -n -e " 巴哈姆特動畫瘋:\c"
# 尝试获取成功的结果
local result="$(curl -4 --user-agent "${UA_Browser}" --output /dev/null --write-out "%{url_effective}" --max-time 30 -fsSL https://ani.gamer.com.tw/animePay.php)"
if [ "$?" = "0" ]; then
if [ "${result}" = "https://user.gamer.com.tw/login.php" ]; then
echo -n -e "\r 巴哈姆特動畫瘋:\t${Font_Green}是${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BahamutAnime="是"
elif [ "${result}" = "https://ani.gamer.com.tw/animePay.php" ]; then
echo -n -e "\r 巴哈姆特動畫瘋:\t${Font_Red}否${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BahamutAnime="否"
else
echo -n -e "\r 巴哈姆特動畫瘋:\t${Font_Yellow}失败-解析失败${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BahamutAnime="测试失败 (解析失败)"
fi
else
echo -e "\r 巴哈姆特動畫瘋:\t${Font_Yellow}失败-网络连接异常${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BahamutAnime="测试失败 (网络连接异常)"
fi
}
# 流媒体解锁测试-哔哩哔哩港澳台限定
Function_MediaUnlockTest_BilibiliHKMCTW() {
echo -n -e " 哔哩哔哩-港澳台限定:\c"
local randsession="$(cat /dev/urandom | head -n 32 | md5sum | head -c 32)"
# 尝试获取成功的结果
local result="$(curl --user-agent "${UA_Browser}" -4 -fsSL --max-time 30 "https://api.bilibili.com/pgc/player/web/playurl?avid=18281381&cid=29892777&qn=0&type=&otype=json&ep_id=183799&fourk=1&fnver=0&fnval=16&session=${randsession}&module=bangumi")"
if [ "$?" = "0" ]; then
local result="$(PharseJSON "${result}" "code")"
if [ "$?" = "0" ]; then
if [ "${result}" = "0" ]; then
echo -n -e "\r 哔哩哔哩-港澳台限定:\t${Font_Green}是${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BilibiliHKMCTW="是"
elif [ "${result}" = "-10403" ]; then
echo -n -e "\r 哔哩哔哩-港澳台限定:\t${Font_Red}否${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BilibiliHKMCTW="否"
else
echo -n -e "\r 哔哩哔哩-港澳台限定:\t${Font_Red}失败-返回值异常${Font_Suffix} ${Font_SkyBlue}(${result})${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BilibiliHKMCTW="测试失败 (返回值异常)"
fi
else
echo -n -e "\r 哔哩哔哩-港澳台限定:\t${Font_Red}失败-解析失败${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BilibiliHKMCTW="测试失败 (解析失败)"
fi
else
echo -n -e "\r 哔哩哔哩-港澳台限定:\t${Font_Red}失败-网络连接异常${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BilibiliHKMCTW="测试失败 (网络连接异常)"
fi
}
# 流媒体解锁测试-哔哩哔哩台湾限定
Function_MediaUnlockTest_BilibiliTW() {
echo -n -e " 哔哩哔哩-台湾限定:\c"
local randsession="$(cat /dev/urandom | head -n 32 | md5sum | head -c 32)"
# 尝试获取成功的结果
local result="$(curl --user-agent "${UA_Browser}" -4 -fsSL --max-time 30 "https://api.bilibili.com/pgc/player/web/playurl?avid=50762638&cid=100279344&qn=0&type=&otype=json&ep_id=268176&fourk=1&fnver=0&fnval=16&session=${randsession}&module=bangumi")"
if [ "$?" = "0" ]; then
local result="$(PharseJSON "${result}" "code")"
if [ "$?" = "0" ]; then
if [ "${result}" = "0" ]; then
echo -n -e "\r 哔哩哔哩-台湾限定:\t${Font_Green}是${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BilibiliTW="是"
elif [ "${result}" = "-10403" ]; then
echo -n -e "\r 哔哩哔哩-台湾限定:\t${Font_Red}否${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BilibiliTW="否"
else
echo -n -e "\r 哔哩哔哩-台湾限定:\t${Font_Red}失败-返回值异常${Font_Suffix} ${Font_SkyBlue}(${result})${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BilibiliTW="测试失败 (返回值异常)"
fi
else
echo -n -e "\r 哔哩哔哩-台湾限定:\t${Font_Red}失败-解析失败${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BilibiliTW="测试失败 (解析失败)"
fi
else
echo -n -e "\r 哔哩哔哩-台湾限定:\t${Font_Red}失败-网络连接异常${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BilibiliTW="测试失败 (网络连接异常)"
fi
}
# =============== Speedtest 部分 ===============
Run_Speedtest() {
# 调用方式: Run_Speedtest "服务器ID" "节点名称(用于显示)"
isFailed="0"
mkdir -p ${WorkDir}/Speedtest/ >/dev/null 2>&1
if [ -f "/usr/sbin/speedtest-cli" ]; then
Speedtest_Exec="speedtest-cli"
else
Speedtest_Exec="speedtest"
fi
if [ "${LBench_Flag_Speedtest_DisablePreAllocate}" = "1" ]; then
Speedtest_Exec="${Speedtest_Exec} --no-pre-allocate "
fi
echo -n -e " $2\c"
Speedtest_Result_Ping=""
Speedtest_Result_Download=""
Speedtest_Result_Upload=""
if [ "$1" = "default" ]; then
local Speedtest_Result="$(${Speedtest_Exec} --simple --bytes 2>&1)"
if [ "$?" != "0" ]; then
local Speedtest_Result="Fail"
fi
else
local Speedtest_Result="$(${Speedtest_Exec} --server $1 --simple --bytes 2>&1)"
if [ "$?" != "0" ]; then
local Speedtest_Result="Fail"
fi
fi
echo "${Speedtest_Result}" | grep "No matched servers|usage|Fail" >/dev/null 2>&1
if [ "$?" != "0" ]; then
Speedtest_Result_Ping="$(echo "${Speedtest_Result}" | awk '(NR==1){print $2}')"
Speedtest_Result_Download="$(echo "${Speedtest_Result}" | awk '(NR==2){print $2}')"
Speedtest_Result_Upload="$(echo "${Speedtest_Result}" | awk '(NR==3){print $2}')"
echo -n -e "\r $2\t\t${Font_SkyBlue}${Speedtest_Result_Upload}${Font_Suffix} MB/s\t${Font_SkyBlue}${Speedtest_Result_Download}${Font_Suffix} MB/s\t${Font_SkyBlue}${Speedtest_Result_Ping}${Font_Suffix} ms\n"
echo -e " $2\t\t${Speedtest_Result_Upload} MB/s\t${Speedtest_Result_Download} MB/s\t${Speedtest_Result_Ping} ms" >>${WorkDir}/Speedtest/result.txt
else
echo -n -e "\r $2\t\t${Font_Red}Fail: $(echo ${Speedtest_Result} | sed -n '1p')${Font_Suffix}\n"
echo -e " $2\t\tFail\n" >>${WorkDir}/Speedtest/result.txt
fi
}
Run_SpeedtestMini() {
# 调用方式: Run_SpeedtestMini "测试服务器(包括完整http/https以及端口号)" "节点名称(用于显示)"
local isFailed="0"
mkdir -p ${WorkDir}/Speedtest/ >/dev/null 2>&1
if [ -f "/usr/sbin/speedtest-cli" ]; then
Speedtest_Exec="speedtest-cli"
else
Speedtest_Exec="speedtest"
fi
if [ "${LBench_Flag_Speedtest_DisablePreAllocate}" = "1" ]; then
Speedtest_Exec="${Speedtest_Exec} --no-pre-allocate "
fi
echo -n -e " $2\c"
Speedtest_Result_Ping=""
Speedtest_Result_Download=""
Speedtest_Result_Upload=""
local Speedtest_Result="$(${Speedtest_Exec} --mini $1 --simple --bytes 2>&1)"
echo "${Speedtest_Result}" | grep "No matched servers\|usage" >/dev/null 2>&1
if [ "$?" != "0" ]; then
Speedtest_Result_Ping="$(echo "${Speedtest_Result}" | awk '(NR==1){print $2}')"
Speedtest_Result_Download="$(echo "${Speedtest_Result}" | awk '(NR==2){print $2}')"
Speedtest_Result_Upload="$(echo "${Speedtest_Result}" | awk '(NR==3){print $2}')"
echo -n -e "\r $2\t\t${Font_SkyBlue}${Speedtest_Result_Upload}${Font_Suffix} MB/s\t${Font_SkyBlue}${Speedtest_Result_Download}${Font_Suffix} MB/s\t${Font_SkyBlue}${Speedtest_Result_Ping}${Font_Suffix} ms\n"
echo -e " $2\t\t${Speedtest_Result_Upload} MB/s\t${Speedtest_Result_Download} MB/s\t${Speedtest_Result_Ping} ms" >>${WorkDir}/Speedtest/result.txt
else
echo -n -e "\r $2\t\t${Font_Red}Fail: $(echo ${Speedtest_Result} | sed -n '1p')${Font_Suffix}\n"
echo -e " $2\t\tFail\n" >>${WorkDir}/Speedtest/result.txt
fi
}
Run_Speedtest_DetectLowMemory() {
SystemInfo_GetMemInfo
local PhyMemFree_MB="$(echo ${LBench_Result_MemoryFree_MB} | awk '{printf "%d\n", $1}')"
local SwapMemFree_MB="$(echo ${LBench_Result_SwapFree_MB} | awk '{printf "%d\n", $1}')"
if [ "${PhyMemFree_MB}" -le "128" ] && [ "${SwapMemFree_MB}" -eq "0" ]; then
echo -e "${Msg_Warning}系统当前可用内存过小 (物理内存可用:${LBench_Result_MemoryFree_MB} MB, 无Swap内存), 可能会导致测试出现MemoryError异常!"
echo -e "${Msg_Warning}已禁用Speedtest模块的预生成数据功能, 上传测试结果准确度可能会降低!"
echo -e "\n"
LBench_Flag_Speedtest_DisablePreAllocate="1"
elif [ "${PhyMemFree_MB}" -ge "128" ] && [ "${SwapMemFree_MB}" -gt "0" ]; then
local TotalAvaPhySwpMem_MB="$(echo ${LBench_Result_MemoryFree_MB} ${LBench_Result_SwapFree_MB} | awk '{print $1+$2}' | awk '{printf "%d", $1}')"
if [ "${TotalAvaPhySwpMem_MB}" -le "300" ]; then
echo -e "${Msg_Warning}系统当前可用物理内存+Swap内存过小 (物理内存可用:${LBench_Result_MemoryFree_MB} MB, 无Swap内存)!"
echo -e "${Msg_Warning}已禁用Speedtest模块的预生成数据功能, 上传测试结果准确度可能会降低!"
echo -e "\n"
LBench_Flag_Speedtest_DisablePreAllocate="1"
fi
fi
}
Function_Speedtest_Fast() {
mkdir -p ${WorkDir}/Speedtest/ >/dev/null 2>&1
echo -e "\n ${Font_Yellow}-> Speedtest.net 网速测试${Font_Suffix}\n"
echo -e "\n-> Speedtest.net 网速测试\n" >>${WorkDir}/Speedtest/result.txt
Check_Speedtest
Run_Speedtest_DetectLowMemory
echo -e " ${Font_Yellow}节点名称\t\t上传速度\t下载速度\tPing延迟${Font_Suffix}"
echo -e " 节点名称\t\t上传速度\t下载速度\tPing延迟" >>${WorkDir}/Speedtest/result.txt
# 默认测试
Run_Speedtest "default" "距离最近测速点"
# Speedtest Mini测试 (自建节点)
#Run_SpeedtestMini "https://testserver.speedtest.ilemonrain.com:3993" "M测试节点"
# 快速测试
Run_Speedtest "9484" "东北-吉林联通"
Run_Speedtest "25637" "华东-上海移动"
Run_Speedtest "16171" "华南-福建移动"
Run_Speedtest "4884" "华南-福建联通"
Run_Speedtest "17251" "华南-广州电信"
# 执行完成, 标记FLAG
LBench_Flag_FinishSpeedtestFast="1"
}
Function_Speedtest_Full() {
mkdir -p ${WorkDir}/Speedtest/ >/dev/null 2>&1
echo -e "\n ${Font_Yellow}-> Speedtest.net 网速测试${Font_Suffix}\n"
echo -e "\n-> Speedtest.net 网速测试\n" >>${WorkDir}/Speedtest/result.txt
Check_Speedtest
Run_Speedtest_DetectLowMemory
echo -e " ${Font_Yellow}节点名称\t\t上传速度\t下载速度\tPing延迟${Font_Suffix}"
echo -e " 节点名称\t\t上传速度\t下载速度\tPing延迟" >>${WorkDir}/Speedtest/result.txt
# 默认测试
Run_Speedtest "default" "距离最近测速点"
# Speedtest Mini测试 (自建节点)
#Run_SpeedtestMini "https://testserver.speedtest.ilemonrain.com:3993" "M测试节点"
# 国内测试
Run_Speedtest "9484" "东北-吉林联通"
Run_Speedtest "16167" "东北-沈阳移动"
Run_Speedtest "17184" "华北-山东联通"
Run_Speedtest "13704" "华中-南京联通"
Run_Speedtest "7509" "华中-杭州电信"
Run_Speedtest "4647" "华中-杭州移动"
Run_Speedtest "3633" "华东-上海电信"
Run_Speedtest "24447" "华东-上海联通"
Run_Speedtest "25637" "华东-上海移动"
Run_Speedtest "16171" "华南-福建移动"
Run_Speedtest "4884" "华南-福建联通"
Run_Speedtest "17251" "华南-广州电信"
Run_Speedtest "5726" "西南-重庆联通"
Run_Speedtest "15863" "西南-南宁移动"
Run_Speedtest "4690" "西北-兰州联通"
Run_Speedtest "3973" "西北-兰州电信"
Run_Speedtest "16145" "西北-兰州移动"
# 执行完成, 标记FLAG
LBench_Flag_FinishSpeedtestFull="1"
}
# =============== 磁盘测试 部分 ===============
Run_DiskTest_DD() {
# 调用方式: Run_DiskTest_DD "测试文件名" "块大小" "写入次数" "测试项目名称"
mkdir -p ${WorkDir}/DiskTest/ >/dev/null 2>&1
SystemInfo_GetVirtType
mkdir -p /.tmp_LBench/DiskTest >/dev/null 2>&1
mkdir -p ${WorkDir}/data >/dev/null 2>&1
local Var_DiskTestResultFile="${WorkDir}/data/disktest_result"
# 将先测试读, 后测试写
echo -n -e " $4\c"
# 清理缓存, 避免影响测试结果
sync
if [ "${Var_VirtType}" != "docker" ] && [ "${Var_VirtType}" != "wsl" ]; then
echo 3 >/proc/sys/vm/drop_caches
fi
# 避免磁盘压力过高, 启动测试前暂停1秒
sleep 1
# 正式写测试
dd if=/dev/zero of=/.tmp_LBench/DiskTest/$1 bs=$2 count=$3 oflag=direct 2>${Var_DiskTestResultFile}
local DiskTest_WriteSpeed_ResultRAW="$(cat ${Var_DiskTestResultFile} | grep -oE "[0-9]{1,}.[0-9]{1,} MB\/s|[0-9]{1,}.[0-9]{1,} MB\/秒|[0-9]{1,} MB\/s|[0-9]{1,} MB\/秒|[0-9]{1,}.[0-9]{1,} GB\/s|[0-9]{1,} MB\/s|[0-9]{1,} MB\/秒|[0-9]{1,}.[0-9]{1,} GB\/秒")"
DiskTest_WriteSpeed="$(echo "${DiskTest_WriteSpeed_ResultRAW}" | sed "s/秒/s/")"
local DiskTest_WriteTime_ResultRAW="$(cat ${Var_DiskTestResultFile} | grep -oE "[0-9]{1,}.[0-9]{1,} s|[0-9]{1,}.[0-9]{1,} 秒")"
DiskTest_WriteTime="$(echo ${DiskTest_WriteTime_ResultRAW} | awk '{print $1}')"
DiskTest_WriteIOPS="$(echo ${DiskTest_WriteTime} $3 | awk '{printf "%d\n",$2/$1}')"
DiskTest_WritePastTime="$(echo ${DiskTest_WriteTime} | awk '{printf "%.2f\n",$1}')"
echo -n -e "\r $4\t\t${Font_SkyBlue}${DiskTest_WriteSpeed} (${DiskTest_WriteIOPS} IOPS, ${DiskTest_WritePastTime}s)${Font_Suffix}\t\t\c"
# 清理结果文件, 准备下一次测试
rm -f ${Var_DiskTestResultFile}
# 清理缓存, 避免影响测试结果
sync
if [ "${Var_VirtType}" != "docker" ] && [ "${Var_VirtType}" != "wsl" ]; then
echo 3 >/proc/sys/vm/drop_caches
fi
sleep 0.5
# 正式读测试
dd if=/.tmp_LBench/DiskTest/$1 of=/dev/null bs=$2 count=$3 iflag=direct 2>${Var_DiskTestResultFile}
local DiskTest_ReadSpeed_ResultRAW="$(cat ${Var_DiskTestResultFile} | grep -oE "[0-9]{1,}.[0-9]{1,} MB\/s|[0-9]{1,}.[0-9]{1,} MB\/秒|[0-9]{1,} MB\/s|[0-9]{1,} MB\/秒|[0-9]{1,}.[0-9]{1,} GB\/s|[0-9]{1,} MB\/s|[0-9]{1,} MB\/秒|[0-9]{1,}.[0-9]{1,} GB\/秒")"
DiskTest_ReadSpeed="$(echo "${DiskTest_ReadSpeed_ResultRAW}" | sed "s/秒/s/")"
local DiskTest_ReadTime_ResultRAW="$(cat ${Var_DiskTestResultFile} | grep -oE "[0-9]{1,}.[0-9]{1,} s|[0-9]{1,}.[0-9]{1,} 秒")"
DiskTest_ReadTime="$(echo ${DiskTest_ReadTime_ResultRAW} | awk '{print $1}')"
DiskTest_ReadIOPS="$(echo ${DiskTest_ReadTime} $3 | awk '{printf "%d\n",$2/$1}')"
DiskTest_ReadPastTime="$(echo ${DiskTest_ReadTime} | awk '{printf "%.2f\n",$1}')"
rm -f ${Var_DiskTestResultFile}
# 输出结果
echo -n -e "\r $4\t\t${Font_SkyBlue}${DiskTest_WriteSpeed} (${DiskTest_WriteIOPS} IOPS, ${DiskTest_WritePastTime}s)${Font_Suffix}\t\t${Font_SkyBlue}${DiskTest_ReadSpeed} (${DiskTest_ReadIOPS} IOPS, ${DiskTest_ReadPastTime}s)${Font_Suffix}\n"
echo -e " $4\t\t${DiskTest_WriteSpeed} (${DiskTest_WriteIOPS} IOPS, ${DiskTest_WritePastTime} 秒)\t\t${DiskTest_ReadSpeed} (${DiskTest_ReadIOPS} IOPS, ${DiskTest_ReadPastTime} 秒)" >>${WorkDir}/DiskTest/result.txt
rm -rf /.tmp_LBench/DiskTest/
}
Function_DiskTest_Fast() {
mkdir -p ${WorkDir}/DiskTest/ >/dev/null 2>&1
echo -e "\n ${Font_Yellow}-> 磁盘性能测试 (4K块/1M块, Direct写入)${Font_Suffix}\n"
echo -e "\n -> 磁盘性能测试 (4K块/1M块, Direct写入)\n" >>${WorkDir}/DiskTest/result.txt
SystemInfo_GetVirtType
SystemInfo_GetOSRelease
if [ "${Var_VirtType}" = "docker" ] || [ "${Var_VirtType}" = "wsl" ]; then
echo -e " ${Msg_Warning}由于系统架构限制, 磁盘测试结果可能会受到缓存影响, 仅供参考!\n"
fi
echo -e " ${Font_Yellow}测试项目\t\t写入速度\t\t\t\t读取速度${Font_Suffix}"
echo -e " 测试项目\t\t写入速度\t\t\t\t读取速度" >>${WorkDir}/DiskTest/result.txt
Run_DiskTest_DD "100MB.test" "4k" "25600" "100MB-4K块"
Run_DiskTest_DD "1000MB.test" "1M" "1000" "1000MB-1M块"
# 执行完成, 标记FLAG
LBench_Flag_FinishDiskTestFast="1"
}
Function_DiskTest_Full() {
mkdir -p ${WorkDir}/DiskTest/ >/dev/null 2>&1
echo -e "\n ${Font_Yellow}-> 磁盘性能测试 (4K块/1M块, Direct写入)${Font_Suffix}\n"
echo -e "\n -> 磁盘性能测试 (4K块/1M块, Direct写入)\n" >>${WorkDir}/DiskTest/result.txt
SystemInfo_GetVirtType
SystemInfo_GetOSRelease
if [ "${Var_VirtType}" = "docker" ] || [ "${Var_VirtType}" = "wsl" ]; then
echo -e " ${Msg_Warning}由于系统架构限制, 磁盘测试结果可能会受到缓存影响, 仅供参考!\n"
fi
echo -e " ${Font_Yellow}测试项目\t\t写入速度\t\t\t\t读取速度${Font_Suffix}"
echo -e " 测试项目\t\t写入速度\t\t\t\t读取速度" >>${WorkDir}/DiskTest/result.txt
Run_DiskTest_DD "10MB.test" "4k" "2560" "10MB-4K块"
Run_DiskTest_DD "10MB.test" "1M" "10" "10MB-1M块"
Run_DiskTest_DD "100MB.test" "4k" "25600" "100MB-4K块"
Run_DiskTest_DD "100MB.test" "1M" "100" "100MB-1M块"
Run_DiskTest_DD "1000MB.test" "4k" "256000" "1000MB-4K块"
Run_DiskTest_DD "1000MB.test" "1M" "1000" "1000MB-1M块"
# 执行完成, 标记FLAG
LBench_Flag_FinishDiskTestFull="1"
}
# =============== BestTrace 部分 ===============
Run_BestTrace() {
mkdir -p ${WorkDir}/BestTrace/ >/dev/null 2>&1
# 调用方式: Run_BestTrace "目标IP" "ICMP/TCP" "最大跃点数" "说明"
if [ "$2" = "tcp" ] || [ "$2" = "TCP" ]; then
echo -e "路由追踪到 $4 (TCP 模式, 最大 $3 跃点)"
echo -e "============================================================"
echo -e "\n路由追踪到 $4 (TCP 模式, 最大 $3 跃点)" >>${WorkDir}/BestTrace/result.txt
echo -e "============================================================" >>${WorkDir}/BestTrace/result.txt
besttrace -g cn -q 1 -T -m $3 $1 | tee -a ${WorkDir}/BestTrace/result.txt
else
echo -e "路由追踪到 $4 (ICMP 模式, 最大 $3 跃点)"
echo -e "============================================================"
echo -e "\n路由追踪到 $4 (ICMP 模式, 最大 $3 跃点)" >>${WorkDir}/BestTrace/result.txt
echo -e "============================================================" >>${WorkDir}/BestTrace/result.txt
besttrace -g cn -q 1 -m $3 $1 | tee -a ${WorkDir}/BestTrace/result.txt
fi
}
Run_BestTrace6() {
# 调用方式: Run_BestTrace "目标IP" "ICMP/TCP" "最大跃点数" "说明"
if [ "$2" = "tcp" ] || [ "$2" = "TCP" ]; then
echo -e "路由追踪到 $4 (TCP 模式, 最大 $3 跃点)"
echo -e "============================================================"
echo -e "\n路由追踪到 $4 (TCP 模式, 最大 $3 跃点)" >>${WorkDir}/BestTrace/result.txt
echo -e "============================================================" >>${WorkDir}/BestTrace/result.txt
besttrace -g cn -6 -q 1 -T -m $3 $1 >>${WorkDir}/BestTrace/result.txt
else
echo -e "路由追踪到 $4 (ICMP 模式, 最大 $3 跃点)"
echo -e "============================================================"
echo -e "路由追踪到 $4 (ICMP 模式, 最大 $3 跃点)" >>${WorkDir}/BestTrace/result.txt
echo -e "============================================================" >>${WorkDir}/BestTrace/result.txt
besttrace -g cn -6 -q 1 -m $3 $1 | tee -a ${WorkDir}/BestTrace/result.txt
fi
}
Function_BestTrace_Fast() {
Check_BestTrace
mkdir -p ${WorkDir}/BestTrace/ >/dev/null 2>&1
if [ "${LBench_Result_NetworkStat}" = "ipv4only" ] || [ "${LBench_Result_NetworkStat}" = "dualstack" ]; then
echo -e "\n ${Font_Yellow}-> 路由追踪测试 (IPV4)${Font_Suffix}\n"
echo -e "\n -> 路由追踪测试 (IPV4)\n" >>${WorkDir}/BestTrace/result.txt
Run_BestTrace "123.125.99.1" "TCP" "30" "北京联通"
Run_BestTrace "180.153.28.1" "TCP" "30" "上海电信"
Run_BestTrace "211.139.145.129" "TCP" "30" "广州移动"
fi