-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.sh
2911 lines (2799 loc) · 152 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 -O- https://ilemonrain.com/download/shell/LemonBench.sh | bash
# (2) curl -fsL https://ilemonrain.com/download/shell/LemonBench.sh | bash
#
# === 全局定义 =====================================
# 全局参数定义
BuildTime="20200228 Intl 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/80.0.3987.87 Safari/537.36"
UA_Dalvik="Dalvik/2.1.0 (Linux; U; Android 9; ALP-AL00 Build/HUAWEIALP-AL00)"
# 字体颜色定义
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}Caught Signal SIGHUP, Exiting ...\n"
Global_TrapSigExit_Action
exit 1
}
# Trap终止信号2 - 处理 (Ctrl+C)
Global_TrapSigExit_Sig2() {
echo -e "\n\n${Msg_Error}Caught Signal SIGINT (or Ctrl+C), Exiting ...\n"
Global_TrapSigExit_Action
exit 1
}
# Trap终止信号3 - 处理
Global_TrapSigExit_Sig3() {
echo -e "\n\n${Msg_Error}Caught Signal SIGQUIT, Exiting ...\n"
Global_TrapSigExit_Action
exit 1
}
# Trap终止信号15 - 处理 (进程被杀)
Global_TrapSigExit_Sig15() {
echo -e "\n\n${Msg_Error}Caught Signal SIGTERM, Exiting ...\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 -fsL -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:-}" \
--data "syntax=${PASTEBIN_SYNTAX:-text}")"
if [ "$?" = "0" ]; then
echo -e "${Msg_Success}Report Generate Success!Please save the follwing link:"
echo -e "${Msg_Info}Report URL:${uploadresult}"
else
echo -e "${Msg_Warning}Report Generate Failure, But you can still read $HOME/LemonBench.Result.txt to get this result!"
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}Loaded Testmode:${Font_SkyBlue}${Global_TestModeTips}${Font_Suffix}"
Function_CheckTracemode
# 清理残留, 为新一次的运行做好准备
echo -e "${Msg_Info}Initializing Running Enviorment, Please wait ..."
rm -rf ${WorkDir}
rm -rf /.tmp_LBench/
mkdir ${WorkDir}/
echo -e "${Msg_Info}Checking Dependency ..."
Check_Virtwhat
Check_JSONQuery
Check_Speedtest
Check_BestTrace
Check_Spoofer
Check_SysBench
echo -e "${Msg_Info}Starting Test ...\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_anice="$(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() {
local sysarch="$(uname -m)"
if [ "${sysarch}" = "unknown" ] || [ "${sysarch}" = "" ]; then
local sysarch="$(arch)"
fi
if [ "${sysarch}" = "x86_64" ]; then
# X86平台 64位
LBench_Result_SystemBit_Short="64"
LBench_Result_SystemBit_Full="amd64"
elif [ "${sysarch}" = "i386" ] || [ "${sysarch}" = "i686" ]; then
# X86平台 32位
LBench_Result_SystemBit_Short="32"
LBench_Result_SystemBit_Full="i386"
elif [ "${sysarch}" = "armv7l" ] || [ "${sysarch}" = "armv8" ] || [ "${sysarch}" = "armv8l" ] || [ "${sysarch}" = "aarch64" ]; then
# ARM平台 暂且将32位/64位统一对待
LBench_Result_SystemBit_Short="arm"
LBench_Result_SystemBit_Full="arm"
else
LBench_Result_SystemBit_Short="unknown"
LBench_Result_SystemBit_Full="unknown"
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}')"
elif [ "$(rpm -qa | grep -o el8 | sort -u)" = "el8" ]; then
Var_CentOSELRepoVersion="8"
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/redhat-release" ]; then # RedHat
Var_OSRelease="rhel"
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_RedHatELRepoVersion="6"
local Var_OSReleaseVersion="$(cat /etc/redhat-release | awk '{print $3}')"
elif [ "$(rpm -qa | grep -o el7 | sort -u)" = "el7" ]; then
Var_RedHatELRepoVersion="7"
local Var_OSReleaseVersion="$(cat /etc/redhat-release | awk '{print $4}')"
elif [ "$(rpm -qa | grep -o el8 | sort -u)" = "el8" ]; then
Var_RedHatELRepoVersion="8"
local Var_OSReleaseVersion="$(cat /etc/redhat-release | awk '{print $4}')"
else
local Var_RedHatELRepoVersion="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: Unknown Linux Branch !]"
fi
}
SystemInfo_GetVirtType() {
if [ -f "/usr/bin/systemd-detect-virt" ]; then
Var_VirtType="$(/usr/bin/systemd-detect-virt)"
# 虚拟机检测
if [ "${Var_VirtType}" = "qemu" ]; then
LBench_Result_VirtType="QEMU"
elif [ "${Var_VirtType}" = "kvm" ]; then
LBench_Result_VirtType="KVM"
elif [ "${Var_VirtType}" = "zvm" ]; then
LBench_Result_VirtType="S390 Z/VM"
elif [ "${Var_VirtType}" = "vmware" ]; then
LBench_Result_VirtType="VMware"
elif [ "${Var_VirtType}" = "microsoft" ]; then
LBench_Result_VirtType="Microsoft Hyper-V"
elif [ "${Var_VirtType}" = "xen" ]; then
LBench_Result_VirtType="XenServer"
elif [ "${Var_VirtType}" = "bochs" ]; then
LBench_Result_VirtType="BOCHS"
elif [ "${Var_VirtType}" = "uml" ]; then
LBench_Result_VirtType="User-mode Linux"
elif [ "${Var_VirtType}" = "parallels" ]; then
LBench_Result_VirtType="Parallels"
elif [ "${Var_VirtType}" = "bhyve" ]; then
LBench_Result_VirtType="FreeBSD Hypervisor"
# 容器虚拟化检测
elif [ "${Var_VirtType}" = "openvz" ]; then
LBench_Result_VirtType="OpenVZ"
elif [ "${Var_VirtType}" = "lxc" ]; then
LBench_Result_VirtType="LXC"
elif [ "${Var_VirtType}" = "lxc-libvirt" ]; then
LBench_Result_VirtType="LXC (libvirt)"
elif [ "${Var_VirtType}" = "systemd-nspawn" ]; then
LBench_Result_VirtType="Systemd nspawn"
elif [ "${Var_VirtType}" = "docker" ]; then
LBench_Result_VirtType="Docker"
elif [ "${Var_VirtType}" = "rkt" ]; then
LBench_Result_VirtType="RKT"
# 特殊处理
elif [ -c "/dev/lxss" ]; then # 处理WSL虚拟化
Var_VirtType="wsl"
LBench_Result_VirtType="Windows Subsystem for Linux (WSL)"
# 未匹配到任何结果, 或者非虚拟机
elif [ "${Var_VirtType}" = "none" ]; then
Var_VirtType="dedicated"
LBench_Result_VirtType="none"
fi
elif [ ! -f "/usr/sbin/virt-what" ]; then
Var_VirtType="Unknown"
LBench_Result_VirtType="[Error: virt-what not found !]"
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_GetUptime() {
local ut="$(cat /proc/uptime | awk '{printf "%d\n",$1}')"
local ut_day="$(echo $result | awk -v ut="$ut" '{printf "%d\n",ut/86400}')"
local ut_hour="$(echo $result | awk -v ut="$ut" -v ut_day="$ut_day" '{printf "%d\n",(ut-(86400*ut_day))/3600}')"
local ut_minute="$(echo $result | awk -v ut="$ut" -v ut_day="$ut_day" -v ut_hour="$ut_hour" '{printf "%d\n",(ut-(86400*ut_day)-(3600*ut_hour))/60}')"
local ut_second="$(echo $result | awk -v ut="$ut" -v ut_day="$ut_day" -v ut_hour="$ut_hour" -v ut_minute="$ut_minute" '{printf "%d\n",(ut-(86400*ut_day)-(3600*ut_hour)-(60*ut_minute))}')"
LBench_Result_SystemInfo_Uptime_Day="$ut_day"
LBench_Result_SystemInfo_Uptime_Hour="$ut_hour"
LBench_Result_SystemInfo_Uptime_Minute="$ut_minute"
LBench_Result_SystemInfo_Uptime_Second="$ut_second"
}
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() {
local Result_IPV4="$(curl --connect-timeout 10 -fsL4 https://ipapi.co/json/)"
local Result_IPV6="$(curl --connect-timeout 10 -fsL6 https://ipapi.co/json/)"
if [ "${Result_IPV4}" != "" ] && [ "${Result_IPV6}" = "" ]; then
LBench_Result_NetworkStat="ipv4only"
elif [ "${Result_IPV4}" = "" ] && [ "${Result_IPV6}" != "" ]; then
LBench_Result_NetworkStat="ipv6only"
elif [ "${Result_IPV4}" != "" ] && [ "${Result_IPV6}" != "" ]; then
LBench_Result_NetworkStat="dualstack"
else
LBench_Result_NetworkStat="unknown"
fi
if [ "${LBench_Result_NetworkStat}" = "ipv4only" ] || [ "${LBench_Result_NetworkStat}" = "dualstack" ]; then
IPAPI_IPV4_ip="$(PharseJSON "${Result_IPV4}" "ip")"
IPAPI_IPV4_city="$(PharseJSON "${Result_IPV4}" "city")"
IPAPI_IPV4_region="$(PharseJSON "${Result_IPV4}" "region")"
IPAPI_IPV4_country="$(PharseJSON "${Result_IPV4}" "country")"
IPAPI_IPV4_country_code="$(PharseJSON "${Result_IPV4}" "country_code")"
IPAPI_IPV4_country_name="$(PharseJSON "${Result_IPV4}" "country_name")"
IPAPI_IPV4_asn="$(PharseJSON "${Result_IPV4}" "asn")"
IPAPI_IPV4_org="$(PharseJSON "${Result_IPV4}" "org")"
if [ "${IPAPI_IPV4_country_name}" = "${IPAPI_IPV4_city}" ]; then
IPAPI_IPV4_city=""
fi
fi
if [ "${LBench_Result_NetworkStat}" = "ipv6only" ] || [ "${LBench_Result_NetworkStat}" = "dualstack" ]; then
IPAPI_IPV6_ip="$(PharseJSON "${Result_IPV6}" "ip")"
IPAPI_IPV6_city="$(PharseJSON "${Result_IPV6}" "city")"
IPAPI_IPV6_region="$(PharseJSON "${Result_IPV6}" "region")"
IPAPI_IPV6_country="$(PharseJSON "${Result_IPV6}" "country")"
IPAPI_IPV6_country_code="$(PharseJSON "${Result_IPV6}" "country_code")"
IPAPI_IPV6_country_name="$(PharseJSON "${Result_IPV6}" "country_name")"
IPAPI_IPV6_asn="$(PharseJSON "${Result_IPV6}" "asn")"
IPAPI_IPV6_org="$(PharseJSON "${Result_IPV6}" "org")"
if [ "${IPAPI_IPV6_country_name}" = "${IPAPI_IPV6_city}" ]; then
IPAPI_IPV6_city=""
fi
fi
if [ "${LBench_Result_NetworkStat}" = "unknown" ]; then
IPAPI_IPV4_ip="-"
IPAPI_IPV4_city=""
IPAPI_IPV4_region=""
IPAPI_IPV4_country="Unknown"
IPAPI_IPV4_country_code="-"
IPAPI_IPV4_asn="Unknown"
IPAPI_IPV4_organization="-"
IPAPI_IPV6_ip="-"
IPAPI_IPV6_city=""
IPAPI_IPV6_region=""
IPAPI_IPV6_country="Unknown"
IPAPI_IPV6_country_code="-"
IPAPI_IPV6_asn="Unknown"
IPAPI_IPV6_organization="-"
fi
}
# SystemInfo_GetNetworkInfo() {
# LBench_Result_LocalIP_IPV4="$(curl --connect-timeout 5 -fsL4 http://api-ipv4.ip.sb)"
# LBench_Result_LocalIP_IPV6="$(curl --connect-timeout 5 -fsL6 http://api-ipv6.ip.sb)"
# if [ "${LBench_Result_LocalIP_IPV4}" != "" ] && [ "${LBench_Result_LocalIP_IPV6}" = "" ]; then
# LBench_Result_NetworkStat="ipv4only"
# local 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 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 Result_IPV4="$(curl -fsL4 --connect-timeout 5 "https://api-ipv4.ip.sb/geoip")"
# local Result_IPV6="$(curl -fsL6 --connect-timeout 5 https://api-ipv6.ip.sb/geoip)"
# # 返回未知值
# else
# LBench_Result_NetworkStat="unknown"
# fi
# # 提取IPV4信息
# if [ "${Result_IPV4}" != "" ]; then
# IPAPI_IPV4_ip="$(PharseJSON "${Result_IPV4}" "ip")"
# IPAPI_IPV4_city="$(PharseJSON "${Result_IPV4}" "city")"
# IPAPI_IPV4_region="$(PharseJSON "${Result_IPV4}" "region")"
# IPAPI_IPV4_country="$(PharseJSON "${Result_IPV4}" "country")"
# IPAPI_IPV4_country_code="$(PharseJSON "${Result_IPV4}" "country_code")"
# IPAPI_IPV4_asn="$(PharseJSON "${Result_IPV4}" "asn")"
# IPAPI_IPV4_organization="$(PharseJSON "${Result_IPV4}" "organization")"
# fi
# if [ "${Result_IPV6}" != "" ]; then
# IPAPI_IPV6_ip="$(PharseJSON "${Result_IPV6}" "ip")"
# IPAPI_IPV6_city="$(PharseJSON "${Result_IPV6}" "city")"
# IPAPI_IPV6_region="$(PharseJSON "${Result_IPV6}" "region")"
# IPAPI_IPV6_country="$(PharseJSON "${Result_IPV6}" "country")"
# IPAPI_IPV6_country_code="$(PharseJSON "${Result_IPV6}" "country_code")"
# IPAPI_IPV6_asn="$(PharseJSON "${Result_IPV6}" "asn")"
# IPAPI_IPV6_organization="$(PharseJSON "${Result_IPV6}" "organization")"
# fi
# }
#
Function_GetSystemInfo() {
clear
echo -e "${Msg_Info}LemonBench Server Test Toolkit Build ${BuildTime}"
echo -e "${Msg_Info}SystemInfo - Collecting System Information ..."
Check_Virtwhat
echo -e "${Msg_Info}Collecting CPU Info ..."
SystemInfo_GetCPUInfo
SystemInfo_GetLoadAverage
SystemInfo_GetSystemBit
SystemInfo_GetCPUStat
echo -e "${Msg_Info}Collecting Memory Info ..."
SystemInfo_GetMemInfo
echo -e "${Msg_Info}Collecting Virtualization Info ..."
SystemInfo_GetVirtType
echo -e "${Msg_Info}Collecting System Info ..."
SystemInfo_GetUptime
echo -e "${Msg_Info}Collecting OS Release Info ..."
SystemInfo_GetOSRelease
echo -e "${Msg_Info}Collecting Disk Info ..."
SystemInfo_GetDiskStat
echo -e "${Msg_Info}Collecting Network Info ..."
SystemInfo_GetNetworkInfo
echo -e "${Msg_Info}Starting Test ..."
clear
}
Function_ShowSystemInfo() {
echo -e "\n ${Font_Yellow}-> System Information${Font_Suffix}\n"
if [ "${Var_OSReleaseVersion_Codename}" != "" ]; then
echo -e " ${Font_Yellow}OS Release:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_OSReleaseFullName}${Font_Suffix}"
else
echo -e " ${Font_Yellow}OS Release:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_OSReleaseFullName}${Font_Suffix}"
fi
echo -e " ${Font_Yellow}CPU Model:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_CPUModelName}${Font_Suffix}"
if [ "${LBench_Result_CPUCacheSize}" != "" ]; then
echo -e " ${Font_Yellow}CPU Cache Size:${Font_Suffix}\t${Font_SkyBlue}${LBench_Result_CPUCacheSize}${Font_Suffix}"
else
echo -e " ${Font_Yellow}CPU Cache Size:${Font_Suffix}\t${Font_SkyBlue}None${Font_Suffix}"
fi
# CPU数量 分支判断
if [ "${LBench_Result_CPUIsPhysical}" = "1" ]; then
# 如果只存在1个物理CPU (单路物理服务器)
if [ "${LBench_Result_CPUPhysicalNumber}" -eq "1" ]; then
echo -e " ${Font_Yellow}CPU Number:${Font_Suffix}\t\t${LBench_Result_CPUPhysicalNumber} ${Font_SkyBlue}Physical CPU${Font_Suffix}, ${LBench_Result_CPUCoreNumber} ${Font_SkyBlue}Core(s)${Font_Suffix}, ${LBench_Result_CPUThreadNumber} ${Font_SkyBlue}Thread(s)${Font_Suffix}"
# 存在多个CPU, 继续深入分析检测 (多路物理服务器)
elif [ "${LBench_Result_CPUPhysicalNumber}" -ge "2" ]; then
echo -e " ${Font_Yellow}CPU Number:${Font_Suffix}\t\t${LBench_Result_CPUPhysicalNumber} ${Font_SkyBlue}Physical CPU(s)${Font_Suffix}, ${LBench_Result_CPUCoreNumber} ${Font_SkyBlue}Core(s)/CPU${Font_Suffix}, ${LBench_Result_CPUSiblingsNumber} ${Font_SkyBlue}Thread(s)/CPU${Font_Suffix} (Total ${Font_SkyBlue}${LBench_Result_CPUTotalCoreNumber}${Font_Suffix} Core(s), ${Font_SkyBlue}${LBench_Result_CPUProcessorNumber}${Font_Suffix} Thread(s))"
# 针对树莓派等特殊情况做出检测优化
elif [ "${LBench_Result_CPUThreadNumber}" = "0" ] && [ "${LBench_Result_CPUProcessorNumber} " -ge "1" ]; then
echo -e " ${Font_Yellow}CPU Number:${Font_Suffix}\t\t${LBench_Result_CPUProcessorNumber} ${Font_SkyBlue}Cores${Font_Suffix}"
fi
if [ "${LBench_Result_CPUVirtualization}" = "1" ]; then
echo -e " ${Font_Yellow}VirtReady:${Font_Suffix}\t\t${Font_SkyBlue}Yes${Font_Suffix} ${Font_SkyBlue}(Based on${Font_Suffix} ${LBench_Result_CPUVirtualizationType}${Font_SkyBlue})${Font_Suffix}"
else
echo -e " ${Font_Yellow}VirtReady:${Font_Suffix}\t\t${Font_SkyRed}No${Font_Suffix}"
fi
elif [ "${Var_VirtType}" = "openvz" ]; then
echo -e " ${Font_Yellow}CPU Number:${Font_Suffix}\t\t${LBench_Result_CPUThreadNumber} ${Font_SkyBlue}vCPU${Font_Suffix} (${LBench_Result_CPUCoreNumber} ${Font_SkyBlue}Host Core/Thread${Font_Suffix})"
else
echo -e " ${Font_Yellow}CPU Number:${Font_Suffix}\t\t${LBench_Result_CPUThreadNumber} ${Font_SkyBlue}vCPU${Font_Suffix}"
fi
echo -e " ${Font_Yellow}Virt Type:${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}Memory Usage:${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}Memory Usage:${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}Memory Usage:${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}Memory Usage:${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="[ No Swapfile / Swap partition ]"
echo -e " ${Font_Yellow}Swap Usage:${Font_Suffix}\t\t${Font_SkyBlue}[ No Swapfile/Swap Partition ]${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 Usage:${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 Usage:${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 Usage:${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 Usage:${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 Usage:${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}Boot Device:${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}Disk Usage:${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}Disk Usage:${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}Disk Usage:${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}Disk Usage:${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}Disk Usage:${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 Usage:${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}Load (1/5/15min):${Font_Suffix}\t${Font_SkyBlue}${LBench_Result_LoadAverage_1min} ${LBench_Result_LoadAverage_5min} ${LBench_Result_LoadAverage_15min} ${Font_Suffix}"
# 系统开机时间
echo -e " ${Font_Yellow}Uptime:${Font_Suffix}\t\t${Font_SkyBlue}${LBench_Result_SystemInfo_Uptime_Day} Days, ${LBench_Result_SystemInfo_Uptime_Hour} Hours, ${LBench_Result_SystemInfo_Uptime_Minute} Minutes, ${LBench_Result_SystemInfo_Uptime_Second} Seconds${Font_Suffix}"
# 执行完成, 标记FLAG
LBench_Flag_FinishSystemInfo="1"
}
Function_ShowNetworkInfo() {
echo -e "\n ${Font_Yellow}-> Network Infomation${Font_Suffix}\n"
if [ "${LBench_Result_NetworkStat}" = "ipv4only" ] || [ "${LBench_Result_NetworkStat}" = "dualstack" ]; then
if [ "${IPAPI_IPV4_ip}" != "" ]; then
echo -e " ${Font_Yellow}IPV4 - IP Address:${Font_Suffix}\t${Font_SkyBlue}[${IPAPI_IPV4_country_code}] ${IPAPI_IPV4_ip}${Font_Suffix}"
echo -e " ${Font_Yellow}IPV4 - ASN Info:${Font_Suffix}\t${Font_SkyBlue}${IPAPI_IPV4_asn} (${IPAPI_IPV4_org})${Font_Suffix}"
echo -e " ${Font_Yellow}IPV4 - Region:${Font_Suffix}\t\t${Font_SkyBlue}${IPAPI_IPV4_country_name} ${IPAPI_IPV4_region} ${IPAPI_IPV4_city}${Font_Suffix}"
else
echo -e " ${Font_Yellow}IPV6 - IP Address:${Font_Suffix}\t${Font_Red}Error: API Query Failed${Font_Suffix}"
fi
fi
if [ "${LBench_Result_NetworkStat}" = "ipv6only" ] || [ "${LBench_Result_NetworkStat}" = "dualstack" ]; then
if [ "${IPAPI_IPV6_ip}" != "" ]; then
echo -e " ${Font_Yellow}IPV6 - IP Address:${Font_Suffix}\t${Font_SkyBlue}[${IPAPI_IPV6_country_code}] ${IPAPI_IPV6_ip}${Font_Suffix}"
echo -e " ${Font_Yellow}IPV6 - ASN Info:${Font_Suffix}\t${Font_SkyBlue}${IPAPI_IPV6_asn} (${IPAPI_IPV6_org})${Font_Suffix}"
echo -e " ${Font_Yellow}IPV6 - Region:${Font_Suffix}\t\t${Font_SkyBlue}${IPAPI_IPV6_country_name} ${IPAPI_IPV6_region} ${IPAPI_IPV6_city}${Font_Suffix}"
else
echo -e " ${Font_Yellow}IPV6 - IP Address:${Font_Suffix}\t${Font_Red}Error: API Query Failed${Font_Suffix}"
fi
fi
# 执行完成, 标记FLAG
LBench_Flag_FinishNetworkInfo="1"
}
# =============== 测试启动与结束动作 ===============
Function_BenchStart() {
clear
LBench_Result_BenchStartTime="$(date +"%Y-%m-%d %H:%M:%S")"
LBench_Result_BenchStartTimestamp="$(date +%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}Bench Start Time:${Font_Suffix} ${Font_SkyBlue}${LBench_Result_BenchStartTime}${Font_Suffix}"
echo -e " ${Msg_Info}${Font_Yellow}Test Mode:${Font_Suffix} ${Font_SkyBlue}${Global_TestModeTips}${Font_Suffix}"
echo -e " "
}
Function_BenchFinish() {
# 清理临时文件
LBench_Result_BenchFinishTime="$(date +"%Y-%m-%d %H:%M:%S")"
LBench_Result_BenchFinishTimestamp="$(date +%s)"
LBench_Result_TimeElapsedSec="$(echo "$LBench_Result_BenchFinishTimestamp $LBench_Result_BenchStartTimestamp" | awk '{print $1-$2}')"
echo -e ""
echo -e "=========================================================================================="
echo -e " "
echo -e " ${Msg_Info}${Font_Yellow}Bench Finish Time:${Font_Suffix} ${Font_SkyBlue}${LBench_Result_BenchFinishTime}${Font_Suffix}"
echo -e " ${Msg_Info}${Font_Yellow}Time Elapsed:${Font_Suffix} ${Font_SkyBlue}${LBench_Result_TimeElapsedSec} seconds${Font_Suffix}"
echo -e " "
}
# =============== 流媒体解锁测试 部分 ===============
# 流媒体解锁测试
Function_MediaUnlockTest() {
echo -e " "
echo -e "${Font_Yellow} -> Media Unlock Test ${Font_Suffix}"
echo -e " "
Function_MediaUnlockTest_HBONow
Function_MediaUnlockTest_BahamutAnime
Function_MediaUnlockTest_AbemaTV_IPTest
Function_MediaUnlockTest_PCRJP
Function_MediaUnlockTest_BilibiliChinaMainland
Function_MediaUnlockTest_BilibiliHKMCTW
Function_MediaUnlockTest_BilibiliTW
LBench_Flag_FinishMediaUnlockTest="1"
}
# 流媒体解锁测试-HBO Now
Function_MediaUnlockTest_HBONow() {
echo -n -e " HBO Now:\t\t\t\t->\c"
# 尝试获取成功的结果
local result="$(curl --user-agent "${UA_Browser}" -4 -fsL --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\t\t${Font_Green}Yes${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_HBONow="Yes"
elif [ "${result}" = "http://hbogeo.cust.footprint.net/hbonow/geo.html" ] || [ "${result}" = "http://geocust.hbonow.com/hbonow/geo.html" ]; then
echo -n -e "\r HBO Now:\t\t\t\t${Font_Red}No${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_HBONow="No"
else
echo -n -e "\r HBO Now:\t\t\t\t${Font_Yellow}Failed (due to parse fail)${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_HBONow="Failed (due to parse fail)"
fi
else
# 下载页面失败,返回错误代码
echo -e "\r HBO Now:\t\t\t\t${Font_Yellow}Failed (due to network fail)${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_HBONow="Failed (due to network fail)"
fi
}
# 流媒体解锁测试-动画疯
Function_MediaUnlockTest_BahamutAnime() {
echo -n -e " Bahamut Anime:\t\t\t\t->\c"
# 尝试获取成功的结果
# local result="$(curl -4 --user-agent "${UA_Browser}" --output /dev/null --write-out "%{url_effective}" --max-time 30 -fsL https://ani.gamer.com.tw/animePay.php)"
local tmpresult="$(curl -4 --user-agent "${UA_Browser}" --max-time 30 -fsL 'https://ani.gamer.com.tw/ajax/token.php?adID=89422&sn=14667')"
if [ "$?" != "0" ]; then
echo -n -e "\r Bahamut Anime:\t\t\t\t${Font_Red}Failed (due to network fail)${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BahamutAnime="Failed (due to network fail)"
return 1
fi
local result="$(echo $tmpresult | jq -r .animeSn)"
if [ "$result" != "null" ]; then
resultverify="$(echo $result | grep -oE '[0-9]{1,}')"
if [ "$?" = "0" ]; then
echo -n -e "\r Bahamut Anime:\t\t\t\t${Font_Green}Yes${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BahamutAnime="Yes"
else
echo -n -e "\r Bahamut Anime:\t\t\t\t${Font_Red}Failed (due to parse fail)${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BahamutAnime="Failed (due to parse fail)"
fi
else
local result="$(echo $tmpresult | jq -r .error.code)"
if [ "$result" != "null" ]; then
resultverify="$(echo $result | grep -oE '[0-9]{1,}')"
if [ "$?" = "0" ]; then
echo -n -e "\r Bahamut Anime:\t\t\t\t${Font_Red}No${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BahamutAnime="No"
else
echo -n -e "\r Bahamut Anime:\t\t\t\t${Font_Red}Failed (due to parse fail)${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BahamutAnime="Failed (due to parse fail)"
fi
else
echo -n -e "\r Bahamut Anime:\t\t\t\t${Font_Red}Failed (due to parse fail)${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BahamutAnime="Failed (due to parse fail)"
fi
fi
}
# 流媒体解锁测试-哔哩哔哩大陆限定
Function_MediaUnlockTest_BilibiliChinaMainland() {
echo -n -e " BiliBili China Mainland Only:\t\t->\c"
local randsession="$(cat /dev/urandom | head -n 32 | md5sum | head -c 32)"
# 尝试获取成功的结果
local result="$(curl --user-agent "${UA_Browser}" -4 -fsL --max-time 30 "https://api.bilibili.com/pgc/player/web/playurl?avid=82846771&qn=0&type=&otype=json&ep_id=307247&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 BiliBili China Mainland Only:\t\t${Font_Green}Yes${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_ChinaMainland="Yes"
elif [ "${result}" = "-10403" ]; then
echo -n -e "\r BiliBili China Mainland Only:\t\t${Font_Red}No${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_ChinaMainland="No"
else
echo -n -e "\r BiliBili China Mainland Only:\t\t${Font_Red}Failed (due to unknown return)${Font_Suffix} ${Font_SkyBlue}(${result})${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_ChinaMainland="Failed (due to unknown return)"
fi
else
echo -n -e "\r BiliBili China Mainland Only:\t\t${Font_Red}Failed (due to parse fail)${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_ChinaMainland="Failed (due to parse fail)"
fi
else
echo -n -e "\r BiliBili China Mainland Only:\t\t${Font_Red}Failed (due to network fail)${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_ChinaMainland="Failed (due to network fail)"
fi
}
# 流媒体解锁测试-哔哩哔哩港澳台限定
Function_MediaUnlockTest_BilibiliHKMCTW() {
echo -n -e " BiliBili Hongkong/Macau/Taiwan:\t->\c"
local randsession="$(cat /dev/urandom | head -n 32 | md5sum | head -c 32)"
# 尝试获取成功的结果
local result="$(curl --user-agent "${UA_Browser}" -4 -fsL --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 BiliBili Hongkong/Macau/Taiwan:\t${Font_Green}Yes${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BilibiliHKMCTW="Yes"
elif [ "${result}" = "-10403" ]; then
echo -n -e "\r BiliBili Hongkong/Macau/Taiwan:\t${Font_Red}No${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BilibiliHKMCTW="No"
else
echo -n -e "\r BiliBili Hongkong/Macau/Taiwan:\t${Font_Red}Failed (due to unknown return)${Font_Suffix} ${Font_SkyBlue}(${result})${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BilibiliHKMCTW="Failed (due to unknown return)"
fi
else
echo -n -e "\r BiliBili Hongkong/Macau/Taiwan:\t${Font_Red}Failed (due to parse fail)${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BilibiliHKMCTW="Failed (due to parse fail)"
fi
else
echo -n -e "\r BiliBili Hongkong/Macau/Taiwan:\t${Font_Red}Failed (due to network fail)${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BilibiliHKMCTW="Failed (due to network fail)"
fi
}
# 流媒体解锁测试-哔哩哔哩台湾限定
Function_MediaUnlockTest_BilibiliTW() {
echo -n -e " Bilibili Taiwan Only:\t\t\t->\c"
local randsession="$(cat /dev/urandom | head -n 32 | md5sum | head -c 32)"
# 尝试获取成功的结果
local result="$(curl --user-agent "${UA_Browser}" -4 -fsL --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 Bilibili Taiwan Only:\t\t\t${Font_Green}Yes${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BilibiliTW="Yes"
elif [ "${result}" = "-10403" ]; then
echo -n -e "\r Bilibili Taiwan Only:\t\t\t${Font_Red}No${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BilibiliTW="No"
else
echo -n -e "\r Bilibili Taiwan Only:\t\t\t${Font_Red}Failed (due to unknown return)${Font_Suffix} ${Font_SkyBlue}(${result})${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BilibiliTW="Failed (due to unknown return)"
fi
else
echo -n -e "\r Bilibili Taiwan Only:\t\t\t${Font_Red}Failed (due to parse fail)${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BilibiliTW="Failed (due to parse fail)"
fi
else
echo -n -e "\r 哔哩哔哩-台湾限定:\t${Font_Red}Failed (due to network fail)${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_BilibiliTW="Failed (due to network fail)"
fi
}
# 流媒体解锁测试-Abema.TV
#
Function_MediaUnlockTest_AbemaTV_IPTest() {
echo -n -e " Abema.TV:\t\t\t\t\c"
#
# 第一轮判断: 判断IP是否为日本IP (通过Akamai)
# 如果不是日本IP, 后续没必要继续判断了
local result="$(curl --user-agent "${UA_Browser}" -4 -fsL --write-out %{http_code} --max-time 30 --output /dev/null http://abematv.akamaized.net/region)"
if [ "$?" = "0" ]; then
if [ "${result}" = "200" ]; then
# 当Akamai 返回 HTTP 200 (OK) 时, 继续第二轮判断
local result="$(curl --user-agent "${UA_Browser}" -4 -fsL https://abema.tv/now-on-air/abema-news)"
local result="$(curl --user-agent "${UA_Browser}" -4 -fsL https://abema.tv/now-on-air/abema-news)"
local result1="$(echo $result | awk -F ' = ' '/window.__CLIENT_REGION__/{print $2$3}' | grep -oP '(?<='isAllowed'":)[0-9A-Za-z]+')"
local result2="$(echo $result | awk -F ' = ' '/window.__CLIENT_REGION__/{print $2$3}' | grep -oP '(?<='status'":)[0-9A-Za-z]+')"
if [ "${result1}" = "true" ] && [ "${result2}" = "true" ]; then
echo -n -e "\r Abema.TV:\t\t\t\t${Font_Green}Yes${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_AbemaTV_IPTest="Yes"
elif [ "${result1}" = "true" ] && [ "${result2}" = "false" ]; then
echo -n -e "\r Abema.TV:\t\t\t\t${Font_Green}Yes${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_AbemaTV_IPTest="Yes"
elif [ "${result1}" = "false" ] && [ "${result2}" = "true" ]; then
echo -n -e "\r Abema.TV:\t\t\t\t${Font_Red}No${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_AbemaTV_IPTest="No"
elif [ "${result1}" = "false" ] && [ "${result2}" = "false" ]; then
echo -n -e "\r Abema.TV:\t\t\t\t${Font_Red}No${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_AbemaTV_IPTest="No"
else
echo -n -e "\r Abema.TV:\t\t\t\t${Font_Red}Failed (Unexpected Return Value)${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_AbemaTV_IPTest="Failed (Unexpected Return Value)"
fi
elif [ "${result}" = "403" ]; then
echo -n -e "\r Abema.TV:\t\t\t\t${Font_Red}No${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_AbemaTV_IPTest="No"
elif [ "${result}" = "404" ]; then
echo -n -e "\r Abema.TV:\t\t\t\t${Font_Red}Failed (HTTP 404 Caught)${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_AbemaTV_IPTest="Failed (HTTP 404 Caught)"
elif [ "${result}" = "000" ]; then
echo -n -e "\r Abema.TV:\t\t\t\t${Font_Red}No${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_AbemaTV_IPTest="No"
else
echo -n -e "\r Abema.TV:\t\t\t\t${Font_Red}Failed (Unexpected HTTP Code)${Font_Suffix} ${Font_SkyBlue}(${result})${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_AbemaTV_IPTest="Failed (Unexpected HTTP Code)"
fi
else
echo -n -e "\r Abema.TV:\t\t\t\t${Font_Red}Failed (Network Connection)${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_AbemaTV_IPTest="Failed (Network Connection)"
fi
}
Function_MediaUnlockTest_PCRJP() {
echo -n -e " Princess Connect Re:Dive (Beta):\t\c"
# 测试,连续请求两次 (单独请求一次可能会返回35, 第二次开始变成0)
local result="$(curl --user-agent "${UA_Dalvik}" -4 -fsL --write-out %{http_code} --max-time 30 --output /dev/null --ciphers 'DEFAULT:!DH' https://app.priconne-redive.jp)"
local result="$(curl --user-agent "${UA_Dalvik}" -4 -fsL --write-out %{http_code} --max-time 30 --output /dev/null --ciphers 'DEFAULT:!DH' https://app.priconne-redive.jp)"
local retval="$?"
if [ "$retval" = "35" ]; then
echo -n -e "\r Princess Connect Re:Dive (Beta)\t${Font_Red}No${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_PCRJP="No"
elif [ "$retval" = "7" ]; then
echo -n -e "\r Princess Connect Re:Dive (Beta)\t${Font_Red}Failed (Network Connection)${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_PCRJP="Failed (Network Connection)"
elif [ "$retval" = "0" ]; then
if [ "$result" = "404" ]; then
echo -n -e "\r Princess Connect Re:Dive (Beta)\t${Font_Green}Yes${Font_Suffix}\n"
LemonBench_Result_MediaUnlockTest_PCRJP="Yes"