forked from LemonBench/LemonBench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LemonBench.sh
1933 lines (1933 loc) · 107 KB
/
LemonBench.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
#!/usr/bin/env bash
#
# LemonBench-Next - 下一代Linux性能基准测试工具
# Author: iLemonrain <[email protected]>
#
# ===== 全局变量 =====
# -> LemonBench工作基础路径
GlobalVar_BaseDir="$HOME/.LemonBench"
# -> LemonBench默认测试预置 (fast|full)
GlobalVar_BenchPreset="none"
# -> 是否在测试结束后自动上传测试报告 (0|1)
GlobalVar_UploadReport="1"
# 设置LemonBench的BenchUA, 此参数由作者维护, 并在某些场景下会作为验证字符串, 您不应该随意修改这里的值
GlobalVar_UA_LemonBench="LemonBench v3/$GlobalVar_LemonBench_Version"
GlobalVar_LemonBench_Version="2023.06.22-Stable"
# 设置LemonBench的浏览器UA, 此参数由作者维护, 并在某些场景下会作为验证字符串, 您不应该随意修改这里的值
GlobalVar_UA_WebBrowser="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"
# 设置LemonBench的手机UA, 此参数由作者维护, 并在某些场景下会作为验证字符串, 您不应该随意修改这里的值
GlobalVar_UA_Dalvik="Dalvik/2.1.0 (Linux; U; Android 9; ALP-AL00 Build/HUAWEIALP-AL00)"
# 设置LemonBench的UnityPlayer UA, 此参数由作者维护, 并在某些场景下会作为验证字符串, 您不应该随意修改这里的值
GlobalVar_UA_UnityPlayer="UnityPlayer/2019.4.1f1 (UnityWebRequest/1.0, libcurl/7.52.0-DEV)"
# 设置curl命令的超时时间 (默认值: 30)
GlobalVar_CurlMaxTime="10"
# -> 路由追踪测试 - 使用工具 (nexttrace|worsttrace)
GlobalVar_TracerouteBinary="nexttrace"
# -> 路由追踪测试 - 使用协议 (icmp|tcp)
GlobalVar_TracerouteMode="icmp"
# -> 路由追踪测试 - 最大跳数 (10~99)
GlobalVar_TracerouteMaxHop="30"
# -> 字体颜色定义 (彩色输出)
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}[WARN]${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}[FAIL]${Font_Suffix}"
Msg_Time="$(date +"[%Y/%m/%d %T]")"
#
# -> 全局函数 - JSON解析
function BenchExec_PharseJSON() {
echo -n "$1" | jq -r "$2" 2>/dev/null
}
#
# ===========================================================================
# -> 系统信息模块 (Entrypoint) -> 执行
function BenchFunc_Systeminfo_GetSysteminfo() {
BenchAPI_Systeminfo_GetCPUinfo
BenchAPI_Systeminfo_GetVMMinfo
BenchAPI_Systeminfo_GetMemoryinfo
BenchAPI_Systeminfo_GetDiskinfo
BenchAPI_Systeminfo_GetOSReleaseinfo
BenchAPI_Systeminfo_GetLinuxKernelinfo
}
# -> 系统信息模块 (DisplayOutput) -> 输出系统信息
function BenchFunc_Systeminfo_ShowSysteminfo() {
echo -e "\n${Font_Yellow} -> System Information${Font_Suffix}\n"
echo -e " ${Font_Yellow}CPU Model Name:${Font_Suffix}\t\t${Font_SkyBlue}${Result_Systeminfo_CPUModelName}"
echo -e " ${Font_Yellow}CPU Cache Size:${Font_Suffix}\t\t${Font_SkyBlue}L1: ${Result_Systeminfo_CPUCacheSizeL1} / L2: ${Result_Systeminfo_CPUCacheSizeL2} / L3: ${Result_Systeminfo_CPUCacheSizeL3}"
if [ "${Result_Systeminfo_isPhysical}" = "1" ]; then
echo -e " ${Font_Yellow}CPU Specifications:${Font_Suffix}\t\t${Font_SkyBlue}${Result_Systeminfo_CPUSockets} Socket(s), ${Result_Systeminfo_CPUCores} Core(s), ${Result_Systeminfo_CPUThreads} Thread(s)"
if [ "${Result_Systeminfo_VirtReady}" = "1" ]; then
if [ "${Result_Systeminfo_IOMMU}" = "1" ]; then
echo -e " ${Font_Yellow}Virtualization Ready:${Font_Suffix}\t\t${Font_SkyBlue}Yes (Based on ${Result_Systeminfo_CPUVMX}, IOMMU Enabled)${Font_Suffix}"
else
echo -e " ${Font_Yellow}Virtualization Ready:${Font_Suffix}\t\t${Font_SkyBlue}Yes (Based on ${Result_Systeminfo_CPUVMX})${Font_Suffix}"
fi
else
echo -e " ${Font_Yellow}Virtualization Ready:${Font_Suffix}\t\t${Font_SkyBlue}No${Font_Suffix}"
fi
elif [ "$Result_Systeminfo_isPhysical" = "0" ]; then
echo -e " ${Font_Yellow}CPU Specifications:${Font_Suffix}\t\t${Font_SkyBlue}${Result_Systeminfo_CPUThreads} vCPU(s)${Font_Suffix}"
if [ "${Result_Systeminfo_VirtReady}" = "1" ]; then
if [ "${Result_Systeminfo_IOMMU}" = "1" ]; then
echo -e " ${Font_Yellow}Virtualization Ready:${Font_Suffix}\t\t${Font_SkyBlue}Yes (Based on ${Result_Systeminfo_CPUVMX}, Nested Virtualization Enabled, IOMMU Enabled${Font_Suffix})"
else
echo -e " ${Font_Yellow}Virtualization Ready:${Font_Suffix}\t\t${Font_SkyBlue}Yes (Based on ${Result_Systeminfo_CPUVMX}, Nested Virtualization Enabled${Font_Suffix})"
fi
else
echo -e " ${Font_Yellow}Virtualization Ready:${Font_Suffix}\t\t${Font_SkyBlue}No${Font_Suffix}"
fi
fi
echo -e " ${Font_Yellow}Virtualization Type:${Font_Suffix}\t\t${Font_SkyBlue}${Result_Systeminfo_VMMType}${Font_Suffix}"
echo -e " ${Font_Yellow}Memory Usage:${Font_Suffix}\t\t\t${Font_SkyBlue}${Result_Systeminfo_Memoryinfo}${Font_Suffix}"
echo -e " ${Font_Yellow}Swap Usage:${Font_Suffix}\t\t\t${Font_SkyBlue}${Result_Systeminfo_Swapinfo}${Font_Suffix}"
echo -e " ${Font_Yellow}Disk Usage:${Font_Suffix}\t\t\t${Font_SkyBlue}${Result_Systeminfo_Diskinfo}${Font_Suffix}"
echo -e " ${Font_Yellow}Boot Disk:${Font_Suffix}\t\t\t${Font_SkyBlue}${Result_Systeminfo_DiskRootPath}${Font_Suffix}"
echo -e " ${Font_Yellow}OS Release:${Font_Suffix}\t\t\t${Font_SkyBlue}${Result_Systeminfo_OSReleaseNameFull}${Font_Suffix}"
echo -e " ${Font_Yellow}Kernel Version:${Font_Suffix}\t\t${Font_SkyBlue}${Result_Systeminfo_LinuxKernelVersion}${Font_Suffix}"
return 0
}
#
# -> 系统信息模块 (Collector) -> 获取CPU信息
function BenchAPI_Systeminfo_GetCPUinfo() {
# CPU 基础信息检测
local r_modelname && r_modelname="$(lscpu -B 2>/dev/null | grep -oP -m1 "(?<=Model name:).*(?=)" | sed -e 's/^[ ]*//g')"
local r_cachesize_l1d_b && r_cachesize_l1d_b="$(lscpu -B 2>/dev/null | grep -oP "(?<=L1d cache:).*(?=)" | sed -e 's/^[ ]*//g')"
local r_cachesize_l1i_b && r_cachesize_l1i_b="$(lscpu -B 2>/dev/null | grep -oP "(?<=L1i cache:).*(?=)" | sed -e 's/^[ ]*//g')"
local r_cachesize_l1_b && r_cachesize_l1_b="$(echo "$r_cachesize_l1d_b" "$r_cachesize_l1i_b" | awk '{printf "%d\n",$1+$2}')"
local r_cachesize_l1_k && r_cachesize_l1_k="$(echo "$r_cachesize_l1_b" | awk '{printf "%.2f\n",$1/1024}')"
local t_cachesize_l1_k && t_cachesize_l1_k="$(echo "$r_cachesize_l1_b" | awk '{printf "%d\n",$1/1024}')"
if [ "$t_cachesize_l1_k" -ge "1024" ]; then
local r_cachesize_l1_m && r_cachesize_l1_m="$(echo "$r_cachesize_l1_k" | awk '{printf "%.2f\n",$1/1024}')"
local r_cachesize_l1="$r_cachesize_l1_m MB"
else
local r_cachesize_l1="$r_cachesize_l1_k KB"
fi
local r_cachesize_l2_b && r_cachesize_l2_b="$(lscpu -B 2>/dev/null | grep -oP "(?<=L2 cache:).*(?=)" | sed -e 's/^[ ]*//g')"
local r_cachesize_l2_k && r_cachesize_l2_k="$(echo "$r_cachesize_l2_b" | awk '{printf "%.2f\n",$1/1024}')"
local t_cachesize_l2_k && t_cachesize_l2_k="$(echo "$r_cachesize_l2_b" | awk '{printf "%d\n",$1/1024}')"
if [ "$t_cachesize_l2_k" -ge "1024" ]; then
local r_cachesize_l2_m && r_cachesize_l2_m="$(echo "$r_cachesize_l2_k" | awk '{printf "%.2f\n",$1/1024}')"
local r_cachesize_l2="$r_cachesize_l2_m MB"
else
local r_cachesize_l2="$r_cachesize_l2_k KB"
fi
local r_cachesize_l3_b && r_cachesize_l3_b="$(lscpu -B 2>/dev/null | grep -oP "(?<=L3 cache:).*(?=)" | sed -e 's/^[ ]*//g')"
local r_cachesize_l3_k && r_cachesize_l3_k="$(echo "$r_cachesize_l3_b" | awk '{printf "%.2f\n",$1/1024}')"
local t_cachesize_l3_k && t_cachesize_l3_k="$(echo "$r_cachesize_l3_b" | awk '{printf "%d\n",$1/1024}')"
if [ "$t_cachesize_l3_k" -ge "1024" ]; then
local r_cachesize_l3_m && r_cachesize_l3_m="$(echo "$r_cachesize_l3_k" | awk '{printf "%.2f\n",$1/1024}')"
local r_cachesize_l3="$r_cachesize_l3_m MB"
else
local r_cachesize_l3="$r_cachesize_l3_k KB"
fi
local r_sockets && r_sockets="$(lscpu -B 2>/dev/null | grep -oP "(?<=Socket\(s\):).*(?=)" | sed -e 's/^[ ]*//g')"
if [ "$r_sockets" -ge "2" ]; then
local r_cores && r_cores="$(lscpu -B 2>/dev/null | grep -oP "(?<=Core\(s\) per socket:).*(?=)" | sed -e 's/^[ ]*//g')"
r_cores="$(echo "$r_sockets" "$r_cores" | awk '{printf "%d\n",$1*$2}')"
local r_threadpercore && r_threadpercore="$(lscpu -B 2>/dev/null | grep -oP "(?<=Thread\(s\) per core:).*(?=)" | sed -e 's/^[ ]*//g')"
local r_threads && r_threads="$(echo "$r_cores" "$r_threadpercore" | awk '{printf "%d\n",$1*$2}')"
r_threads="$(echo "$r_threadpercore" "$r_cores" | awk '{printf "%d\n",$1*$2}')"
else
local r_cores && r_cores="$(lscpu -B 2>/dev/null | grep -oP "(?<=Core\(s\) per socket:).*(?=)" | sed -e 's/^[ ]*//g')"
local r_threadpercore && r_threadpercore="$(lscpu -B 2>/dev/null | grep -oP "(?<=Thread\(s\) per core:).*(?=)" | sed -e 's/^[ ]*//g')"
local r_threads && r_threads="$(echo "$r_cores" "$r_threadpercore" | awk '{printf "%d\n",$1*$2}')"
fi
# CPU AES能力检测
# local t_aes && t_aes="$(awk -F ': ' '/flags/{print $2}' /proc/cpuinfo 2>/dev/null | grep -oE "\baes\b" | sort -u)"
# [[ "${t_aes}" = "aes" ]] && Result_Systeminfo_CPUAES="1" || Result_Systeminfo_CPUAES="0"
# CPU AVX能力检测
# local t_avx && t_avx="$(awk -F ': ' '/flags/{print $2}' /proc/cpuinfo 2>/dev/null | grep -oE "\bavx\b" | sort -u)"
# [[ "${t_avx}" = "avx" ]] && Result_Systeminfo_CPUAVX="1" || Result_Systeminfo_CPUAVX="0"
# CPU AVX512能力检测
# local t_avx512 && t_avx512="$(awk -F ': ' '/flags/{print $2}' /proc/cpuinfo 2>/dev/null | grep -oE "\bavx512\b" | sort -u)"
# [[ "${t_avx512}" = "avx" ]] && Result_Systeminfo_CPUAVX512="1" || Result_Systeminfo_CPUAVX512="0"
# CPU 虚拟化能力检测
local t_vmx_vtx && t_vmx_vtx="$(awk -F ': ' '/flags/{print $2}' /proc/cpuinfo 2>/dev/null | grep -oE "\bvmx\b" | sort -u)"
local t_vmx_svm && t_vmx_svm="$(awk -F ': ' '/flags/{print $2}' /proc/cpuinfo 2>/dev/null | grep -oE "\bsvm\b" | sort -u)"
if [ "$t_vmx_vtx" = "vmx" ]; then
Result_Systeminfo_VirtReady="1"
Result_Systeminfo_CPUVMX="Intel VT-x"
elif [ "$t_vmx_svm" = "svm" ]; then
Result_Systeminfo_VirtReady="1"
Result_Systeminfo_CPUVMX="AMD-V"
else
if [ -c "/dev/kvm" ]; then
Result_Systeminfo_VirtReady="1"
Result_Systeminfo_CPUVMX="unknown"
else
Result_Systeminfo_VirtReady="0"
Result_Systeminfo_CPUVMX="unknown"
fi
fi
# 输出结果
Result_Systeminfo_CPUModelName="$r_modelname"
Result_Systeminfo_CPUSockets="$r_sockets"
Result_Systeminfo_CPUCores="$r_cores"
Result_Systeminfo_CPUThreads="$r_threads"
Result_Systeminfo_CPUCacheSizeL1="$r_cachesize_l1"
Result_Systeminfo_CPUCacheSizeL2="$r_cachesize_l2"
Result_Systeminfo_CPUCacheSizeL3="$r_cachesize_l3"
}
#
# -> 系统信息模块 (Collector) -> 获取内存及Swap信息
function BenchAPI_Systeminfo_GetMemoryinfo() {
# 内存信息
local r_memtotal_kib && r_memtotal_kib="$(awk '/MemTotal/{print $2}' /proc/meminfo | head -n1)"
local r_memtotal_mib && r_memtotal_mib="$(echo "$r_memtotal_kib" | awk '{printf "%.2f\n",$1/1024}')"
local r_memtotal_gib && r_memtotal_gib="$(echo "$r_memtotal_kib" | awk '{printf "%.2f\n",$1/1048576}')"
local r_meminfo_memfree_kib && r_meminfo_memfree_kib="$(awk '/MemFree/{print $2}' /proc/meminfo | head -n1)"
local r_meminfo_buffers_kib && r_meminfo_buffers_kib="$(awk '/Buffers/{print $2}' /proc/meminfo | head -n1)"
local r_meminfo_cached_kib && r_meminfo_cached_kib="$(awk '/Cached/{print $2}' /proc/meminfo | head -n1)"
local r_memfree_kib && r_memfree_kib="$(echo "$r_meminfo_memfree_kib" "$r_meminfo_buffers_kib" "$r_meminfo_cached_kib" | awk '{printf $1+$2+$3}')"
local r_memfree_mib && r_memfree_mib="$(echo "$r_memfree_kib" | awk '{printf "%.2f\n",$1/1024}')"
local r_memfree_gib && r_memfree_gib="$(echo "$r_memfree_kib" | awk '{printf "%.2f\n",$1/1048576}')"
local r_memused_kib && r_memused_kib="$(echo "$r_memtotal_kib" "$r_memfree_kib" | awk '{printf $1-$2}')"
local r_memused_mib && r_memused_mib="$(echo "$r_memused_kib" | awk '{printf "%.2f\n",$1/1024}')"
local r_memused_gib && r_memused_gib="$(echo "$r_memused_kib" | awk '{printf "%.2f\n",$1/1048576}')"
# 交换信息
local r_swaptotal_kib && r_swaptotal_kib="$(awk '/SwapTotal/{print $2}' /proc/meminfo | head -n1)"
local r_swaptotal_mib && r_swaptotal_mib="$(echo "$r_swaptotal_kib" | awk '{printf "%.2f\n",$1/1024}')"
local r_swaptotal_gib && r_swaptotal_gib="$(echo "$r_swaptotal_kib" | awk '{printf "%.2f\n",$1/1048576}')"
local r_swapfree_kib && r_swapfree_kib="$(awk '/SwapFree/{print $2}' /proc/meminfo | head -n1)"
local r_swapfree_mib && r_swapfree_mib="$(echo "$r_swapfree_kib" | awk '{printf "%.2f\n",$1/1024}')"
local r_swapfree_gib && r_swapfree_gib="$(echo "$r_swapfree_kib" | awk '{printf "%.2f\n",$1/1048576}')"
local r_swapused_kib && r_swapused_kib="$(echo "$r_swaptotal_kib" "${r_swapfree_kib}" | awk '{printf $1-$2}')"
local r_swapused_mib && r_swapused_mib="$(echo "$r_swapused_kib" | awk '{printf "%.2f\n",$1/1024}')"
local r_swapused_gib && r_swapused_gib="$(echo "$r_swapused_kib" | awk '{printf "%.2f\n",$1/1048576}')"
# 数据加工
if [ "$r_memused_kib" -lt "1024" ] && [ "$r_memtotal_kib" -lt "1048576" ]; then
Result_Systeminfo_Memoryinfo="$r_memused_kib KiB / $r_memtotal_mib MiB"
elif [ "$r_memused_kib" -lt "1048576" ] && [ "$r_memtotal_kib" -lt "1048576" ]; then
Result_Systeminfo_Memoryinfo="$r_memused_mib MiB / $r_memtotal_mib MiB"
elif [ "$r_memused_kib" -lt "1048576" ] && [ "$r_memtotal_kib" -lt "1073741824" ]; then
Result_Systeminfo_Memoryinfo="$r_memused_mib MiB / $r_memtotal_gib GiB"
else
Result_Systeminfo_Memoryinfo="$r_memused_gib GiB / $r_memtotal_gib GiB"
fi
if [ "$r_swaptotal_kib" -eq "0" ]; then
Result_Systeminfo_Swapinfo="[ no swap partition or swap file detected ]"
elif [ "$r_swapused_kib" -lt "1024" ] && [ "$r_swaptotal_kib" -lt "1048576" ]; then
Result_Systeminfo_Swapinfo="$r_swapused_kib KiB / $r_swaptotal_mib MiB"
elif [ "$r_swapused_kib" -lt "1024" ] && [ "$r_swaptotal_kib" -lt "1073741824" ]; then
Result_Systeminfo_Swapinfo="$r_swapused_kib KiB / $r_swaptotal_gib GiB"
elif [ "$r_swapused_kib" -lt "1048576" ] && [ "$r_swaptotal_kib" -lt "1048576" ]; then
Result_Systeminfo_Swapinfo="$r_swapused_mib MiB / $r_swaptotal_mib MiB"
elif [ "$r_swapused_kib" -lt "1048576" ] && [ "$r_swaptotal_kib" -lt "1073741824" ]; then
Result_Systeminfo_Swapinfo="$r_swapused_mib MiB / $r_swaptotal_gib GiB"
else
Result_Systeminfo_Swapinfo="$r_swapused_gib GiB / $r_swaptotal_gib GiB"
fi
}
#
# -> 系统信息模块 (Collector) -> 获取磁盘信息
function BenchAPI_Systeminfo_GetDiskinfo() {
# 磁盘信息
local r_diskpath_root && r_diskpath_root="$(df -x tmpfs / | awk "NR>1" | sed ":a;N;s/\\n//g;ta" | awk '{print $1}')"
local r_disktotal_kib && r_disktotal_kib="$(df -x tmpfs / | grep -oE "[0-9]{4,}" | awk 'NR==1 {print $1}')"
local r_disktotal_mib && r_disktotal_mib="$(echo "$r_disktotal_kib" | awk '{printf "%.2f\n",$1/1024}')"
local r_disktotal_gib && r_disktotal_gib="$(echo "$r_disktotal_kib" | awk '{printf "%.2f\n",$1/1048576}')"
local r_disktotal_tib && r_disktotal_tib="$(echo "$r_disktotal_kib" | awk '{printf "%.2f\n",$1/1073741824}')"
local r_diskused_kib && r_diskused_kib="$(df -x tmpfs / | grep -oE "[0-9]{4,}" | awk 'NR==2 {print $1}')"
local r_diskused_mib && r_diskused_mib="$(echo "$r_diskused_kib" | awk '{printf "%.2f\n",$1/1024}')"
local r_diskused_gib && r_diskused_gib="$(echo "$r_diskused_kib" | awk '{printf "%.2f\n",$1/1048576}')"
local r_diskused_tib && r_diskused_tib="$(echo "$r_diskused_kib" | awk '{printf "%.2f\n",$1/1073741824}')"
local r_diskfree_kib && r_diskfree_kib="$(df -x tmpfs / | grep -oE "[0-9]{4,}" | awk 'NR==3 {print $1}')"
local r_diskfree_mib && r_diskfree_mib="$(echo "$r_diskfree_kib" | awk '{printf "%.2f\n",$1/1024}')"
local r_diskfree_gib && r_diskfree_gib="$(echo "$r_diskfree_kib" | awk '{printf "%.2f\n",$1/1048576}')"
local r_diskfree_tib && r_diskfree_tib="$(echo "$r_diskfree_kib" | awk '{printf "%.2f\n",$1/1073741824}')"
# 数据加工
Result_Systeminfo_DiskRootPath="$r_diskpath_root"
if [ "$r_diskused_kib" -lt "1048576" ]; then
Result_Systeminfo_Diskinfo="$r_diskused_mib MiB / $r_disktotal_mib MiB"
elif [ "$r_diskused_kib" -lt "1048576" ] && [ "$r_disktotal_kib" -lt "1073741824" ]; then
Result_Systeminfo_Diskinfo="$r_diskused_mib MiB / $r_disktotal_gib GiB"
elif [ "$r_diskused_kib" -lt "1073741824" ] && [ "$r_disktotal_kib" -lt "1073741824" ]; then
Result_Systeminfo_Diskinfo="$r_diskused_gib GiB / $r_disktotal_gib GiB"
elif [ "$r_diskused_kib" -lt "1073741824" ] && [ "$r_disktotal_kib" -ge "1073741824" ]; then
Result_Systeminfo_Diskinfo="$r_diskused_gib GiB / $r_disktotal_tib TiB"
else
Result_Systeminfo_Diskinfo="$r_diskused_tib TiB / $r_disktotal_tib TiB"
fi
}
#
# -> 系统信息模块 (Collector) -> 获取虚拟化信息
function BenchAPI_Systeminfo_GetVMMinfo() {
if [ -f "/usr/bin/systemd-detect-virt" ]; then
local r_vmmtype && r_vmmtype="$(/usr/bin/systemd-detect-virt 2>/dev/null)"
case "${r_vmmtype}" in
kvm)
Result_Systeminfo_VMMType="KVM"
Result_Systeminfo_VMMTypeShort="kvm"
Result_Systeminfo_isPhysical="0"
return 0
;;
xen)
Result_Systeminfo_VMMType="Xen Hypervisor"
Result_Systeminfo_VMMTypeShort="xen"
Result_Systeminfo_isPhysical="0"
return 0
;;
microsoft)
Result_Systeminfo_VMMType="Microsoft Hyper-V"
Result_Systeminfo_VMMTypeShort="microsoft"
Result_Systeminfo_isPhysical="0"
return 0
;;
vmware)
Result_Systeminfo_VMMType="VMware"
Result_Systeminfo_VMMTypeShort="vmware"
Result_Systeminfo_isPhysical="0"
return 0
;;
oracle)
Result_Systeminfo_VMMType="Oracle VirtualBox"
Result_Systeminfo_VMMTypeShort="oracle"
Result_Systeminfo_isPhysical="0"
return 0
;;
parallels)
Result_Systeminfo_VMMType="Parallels"
Result_Systeminfo_VMMTypeShort="parallels"
Result_Systeminfo_isPhysical="0"
return 0
;;
qemu)
Result_Systeminfo_VMMType="QEMU"
Result_Systeminfo_VMMTypeShort="qemu"
Result_Systeminfo_isPhysical="0"
return 0
;;
amazon)
Result_Systeminfo_VMMType="Amazon Virtualization"
Result_Systeminfo_VMMTypeShort="amazon"
Result_Systeminfo_isPhysical="0"
return 0
;;
docker)
Result_Systeminfo_VMMType="Docker"
Result_Systeminfo_VMMTypeShort="docker"
Result_Systeminfo_isPhysical="0"
return 0
;;
openvz)
Result_Systeminfo_VMMType="OpenVZ (Virutozzo)"
Result_Systeminfo_VMMTypeShort="openvz"
Result_Systeminfo_isPhysical="0"
return 0
;;
lxc)
Result_Systeminfo_VMMTypeShort="lxc"
Result_Systeminfo_VMMType="LXC"
Result_Systeminfo_isPhysical="0"
return 0
;;
lxc-libvirt)
Result_Systeminfo_VMMType="LXC (Based on libvirt)"
Result_Systeminfo_VMMTypeShort="lxc-libvirt"
Result_Systeminfo_isPhysical="0"
return 0
;;
uml)
Result_Systeminfo_VMMType="User-mode Linux"
Result_Systeminfo_VMMTypeShort="uml"
Result_Systeminfo_isPhysical="0"
return 0
;;
systemd-nspawn)
Result_Systeminfo_VMMType="Systemd nspawn"
Result_Systeminfo_VMMTypeShort="systemd-nspawn"
Result_Systeminfo_isPhysical="0"
return 0
;;
bochs)
Result_Systeminfo_VMMType="BOCHS"
Result_Systeminfo_VMMTypeShort="bochs"
Result_Systeminfo_isPhysical="0"
return 0
;;
rkt)
Result_Systeminfo_VMMType="RKT"
Result_Systeminfo_VMMTypeShort="rkt"
Result_Systeminfo_isPhysical="0"
return 0
;;
zvm)
Result_Systeminfo_VMMType="S390 Z/VM"
Result_Systeminfo_VMMTypeShort="zvm"
Result_Systeminfo_isPhysical="0"
return 0
;;
none)
Result_Systeminfo_VMMType="Dedicated"
Result_Systeminfo_VMMTypeShort="none"
Result_Systeminfo_isPhysical="1"
if test -f "/sys/class/iommu/dmar0/uevent"; then
Result_Systeminfo_IOMMU="1"
else
Result_Systeminfo_IOMMU="0"
fi
return 0
;;
*)
echo -e "${Msg_Error} BenchAPI_Systeminfo_GetVirtinfo(): invalid result (${r_vmmtype}), please check parameter!"
exit 1
;;
esac
elif [ -f "/.dockerenv" ]; then
Result_Systeminfo_VMMType="Docker"
Result_Systeminfo_VMMTypeShort="docker"
Result_Systeminfo_isPhysical="0"
return 0
elif [ -c "/dev/lxss" ]; then
Result_Systeminfo_VMMType="Windows Subsystem for Linux"
Result_Systeminfo_VMMTypeShort="wsl"
Result_Systeminfo_isPhysical="0"
return 0
else
Result_Systeminfo_VMMType="Dedicated"
Result_Systeminfo_VMMTypeShort="none"
if test -f "/sys/class/iommu/dmar0/uevent"; then
Result_Systeminfo_IOMMU="1"
else
Result_Systeminfo_IOMMU="0"
fi
return 0
fi
}
#
# -> 系统信息模块 (Collector) -> 获取Linux发行版信息
function BenchAPI_Systeminfo_GetOSReleaseinfo() {
local r_arch && r_arch="$(arch)"
Result_Systeminfo_OSArch="$r_arch"
# CentOS/Red Hat 判断
if [ -f "/etc/centos-release" ] || [ -f "/etc/redhat-release" ]; then
Result_Systeminfo_OSReleaseNameShort="centos"
local r_prettyname && r_prettyname="$(grep -oP '(?<=\bPRETTY_NAME=").*(?=")' /etc/os-release)"
local r_elrepo_version && r_elrepo_version="$(rpm -qa | grep -oP "el[0-9]+" | sort -u)"
case "$r_elrepo_version" in
9 | el9)
Result_Systeminfo_OSReleaseVersionShort="9"
Result_Systeminfo_OSReleaseNameFull="$r_prettyname ($r_arch)"
return 0
;;
8 | el8)
Result_Systeminfo_OSReleaseVersionShort="8"
Result_Systeminfo_OSReleaseNameFull="$r_prettyname ($r_arch)"
return 0
;;
7 | el7)
Result_Systeminfo_OSReleaseVersionShort="7"
Result_Systeminfo_OSReleaseNameFull="$r_prettyname ($r_arch)"
return 0
;;
6 | el6)
Result_Systeminfo_OSReleaseVersionShort="6"
Result_Systeminfo_OSReleaseNameFull="$r_prettyname ($r_arch)"
return 0
;;
*)
echo -e "${Msg_Error} BenchAPI_Systeminfo_GetOSReleaseinfo(): invalid result (CentOS/Redhat-$r_prettyname ($r_arch)), please check parameter!"
exit 1
;;
esac
elif [ -f "/etc/lsb-release" ]; then # Ubuntu
Result_Systeminfo_OSReleaseNameShort="ubuntu"
local r_prettyname && r_prettyname="$(grep -oP '(?<=\bPRETTY_NAME=").*(?=")' /etc/os-release)"
Result_Systeminfo_OSReleaseVersion="$(grep -oP '(?<=\bVERSION=").*(?=")' /etc/os-release)"
Result_Systeminfo_OSReleaseVersionShort="$(grep -oP '(?<=\bVERSION_ID=").*(?=")' /etc/os-release)"
Result_Systeminfo_OSReleaseNameFull="$r_prettyname ($r_arch)"
return 0
elif [ -f "/etc/debian_version" ]; then # Debian
Result_Systeminfo_OSReleaseNameShort="debian"
local r_prettyname && r_prettyname="$(grep -oP '(?<=\bPRETTY_NAME=").*(?=")' /etc/os-release)"
Result_Systeminfo_OSReleaseVersion="$(grep -oP '(?<=\bVERSION=").*(?=")' /etc/os-release)"
Result_Systeminfo_OSReleaseVersionShort="$(grep -oP '(?<=\bVERSION_ID=").*(?=")' /etc/os-release)"
Result_Systeminfo_OSReleaseNameFull="$r_prettyname ($r_arch)"
return 0
else
echo -e "${Msg_Error} BenchAPI_Systeminfo_GetOSReleaseinfo(): invalid result ($r_prettyname ($r_arch)), please check parameter!"
exit 1
fi
}
#
# -> 系统信息模块 (Collector) -> 获取Linux内核版本信息
function BenchAPI_Systeminfo_GetLinuxKernelinfo() {
# 获取原始数据
Result_Systeminfo_LinuxKernelVersion="$(uname -r)"
}
#
# ===========================================================================
# -> 网络信息模块 (Entrypoint) -> 执行
function BenchFunc_Networkinfo_GetNetworkinfo() {
BenchAPI_Networkinfo_GetNetworkinfo
}
# -> 网络信息模块 (DisplayOutput) -> 输出网络信息
function BenchFunc_Networkinfo_ShowNetworkinfo() {
echo -e "\n ${Font_Yellow}-> Network Information${Font_Suffix}\n"
if [ "$Result_Networkinfo_NetworkType" = "ipv4" ] || [ "$Result_Networkinfo_NetworkType" = "dualstack" ]; then
echo -e " ${Font_Yellow}IPv4-IP Address:${Font_Suffix}\t\t${Font_SkyBlue}[$Result_Networkinfo_CountryCode4] $Result_Networkinfo_IP4${Font_Suffix}"
echo -e " ${Font_Yellow}IPv4-AS Information:${Font_Suffix}\t\t${Font_SkyBlue}$Result_Networkinfo_NetworkOwner4${Font_Suffix}"
echo -e " ${Font_Yellow}IPv4-GeoIP Location:${Font_Suffix}\t\t${Font_SkyBlue}$Result_Networkinfo_GeoLocation4${Font_Suffix}"
fi
if [ "$Result_Networkinfo_NetworkType" = "ipv6" ] || [ "$Result_Networkinfo_NetworkType" = "dualstack" ]; then
echo -e " ${Font_Yellow}IPv6-IP Address:${Font_Suffix}\t\t${Font_SkyBlue}[$Result_Networkinfo_CountryCode6] $Result_Networkinfo_IP6${Font_Suffix}"
echo -e " ${Font_Yellow}IPv6-AS Information:${Font_Suffix}\t\t${Font_SkyBlue}$Result_Networkinfo_NetworkOwner6${Font_Suffix}"
echo -e " ${Font_Yellow}IPv6-GeoIP Location:${Font_Suffix}\t\t${Font_SkyBlue}$Result_Networkinfo_GeoLocation6${Font_Suffix}"
fi
if [ "$Result_Networkinfo_NetworkType" = "unknown" ]; then
echo -e " ${Font_Yellow}No network information detected${Font_Suffix}"
fi
}
#
# -> 网络信息模块 (Collector) -> 获取网络信息
function BenchAPI_Networkinfo_GetNetworkinfo() {
local r_r4 && r_r4="$(curl --connect-timeout 10 -s4 https://ipapi.co/json/)"
sleep 1
local r_r6 && r_r6="$(curl --connect-timeout 10 -s6 https://ipapi.co/json/)"
local r_r4_error && r_r4_error="$(BenchExec_PharseJSON "$r_r4" ".error")"
local r_r6_error && r_r6_error="$(BenchExec_PharseJSON "$r_r6" ".error")"
if [ "$r_r4_error" = "true" ]; then
local r_r4=""
fi
if [ "$r_r6_error" = "true" ]; then
local r_r6=""
fi
if [ "$r_r4" != "" ] && [ "$r_r6" = "" ]; then
local r_ntype && r_ntype="ipv4"
Result_Networkinfo_NetworkType="ipv4"
elif [ "$r_r4" != "" ] && [ "$r_r6" = "" ]; then
local r_ntype && r_ntype="ipv6"
Result_Networkinfo_NetworkType="ipv6"
elif [ "$r_r4" != "" ] && [ "$r_r6" != "" ]; then
local r_ntype && r_ntype="dualstack"
Result_Networkinfo_NetworkType="dualstack"
else
local r_ntype && r_ntype="unknown"
Result_Networkinfo_NetworkType="unknown"
return 1
fi
if [ "$r_ntype" = "ipv4" ] || [ "$r_ntype" = "dualstack" ]; then
local r_r4_ip && r_r4_ip="$(BenchExec_PharseJSON "$r_r4" ".ip")"
local r_r4_country_name && r_r4_country_name="$(BenchExec_PharseJSON "$r_r4" ".country_name")"
local r_r4_region && r_r4_region="$(BenchExec_PharseJSON "$r_r4" ".region")"
local r_r4_city && r_r4_city="$(BenchExec_PharseJSON "$r_r4" ".city")"
local r_r4_country_code && r_r4_country_code="$(BenchExec_PharseJSON "$r_r4" ".country_code")"
local r_r4_asn && r_r4_asn="$(BenchExec_PharseJSON "$r_r4" ".asn")"
local r_r4_org && r_r4_org="$(BenchExec_PharseJSON "$r_r4" ".org")"
Result_Networkinfo_IP4="$r_r4_ip"
Result_Networkinfo_GeoLocation4="$r_r4_country_name $r_r4_region $r_r4_city"
Result_Networkinfo_CountryCode4="$r_r4_country_code"
Result_Networkinfo_NetworkOwner4="$r_r4_asn - $r_r4_org"
fi
if [ "$r_ntype" = "ipv6" ] || [ "$r_ntype" = "dualstack" ]; then
local r_r6_ip && r_r6_ip="$(BenchExec_PharseJSON "$r_r6" ".ip")"
local r_r6_country_name && r_r6_country_name="$(BenchExec_PharseJSON "$r_r6" ".country_name")"
local r_r6_region && r_r6_region="$(BenchExec_PharseJSON "$r_r6" ".region")"
local r_r6_city && r_r6_city="$(BenchExec_PharseJSON "$r_r6" ".city")"
local r_r6_country_code && r_r6_country_code="$(BenchExec_PharseJSON "$r_r6" ".country_code")"
local r_r6_asn && r_r6_asn="$(BenchExec_PharseJSON "$r_r6" ".asn")"
local r_r6_org && r_r6_org="$(BenchExec_PharseJSON "$r_r6" ".org")"
Result_Networkinfo_IP6="$r_r6_ip"
Result_Networkinfo_GeoLocation6="$r_r6_country_name $r_r6_region $r_r6_city"
Result_Networkinfo_CountryCode6="$r_r6_country_code"
Result_Networkinfo_NetworkOwner6="$r_r6_asn - $r_r6_org"
fi
}
#
# ===========================================================================
#
# -> 流媒体解锁测试模块 (DisplayOutput) - 输出解锁测试结果
function BenchFunc_StreamingServiceUnlockTest_RunTest() {
echo -e "\n ${Font_Yellow}-> Streaming Service Unlock Test${Font_Suffix}"
#
echo -e "\n ${Font_Yellow}Netflix:${Font_Suffix}\t\t\t->\c"
BenchAPI_StreamingServiceUnlockTest_Netflix
echo -n -e "\r ${Font_Yellow}Netflix:${Font_Suffix}\t\t\t${Font_SkyBlue}$Result_StreamingServiceUnlockTest_Netflix${Font_Suffix}"
#
echo -e "\n ${Font_Yellow}HBO Now:${Font_Suffix}\t\t\t->\c"
BenchAPI_StreamingServiceUnlockTest_HBONow
echo -n -e "\r ${Font_Yellow}HBO Now:${Font_Suffix}\t\t\t${Font_SkyBlue}$Result_StreamingServiceUnlockTest_HBONow${Font_Suffix}"
#
echo -e "\n ${Font_Yellow}Youtube Premium:${Font_Suffix}\t\t->\c"
BenchAPI_StreamingServiceUnlockTest_YoutubePremium
echo -n -e "\r ${Font_Yellow}Youtube Premium:${Font_Suffix}\t\t${Font_SkyBlue}$Result_StreamingServiceUnlockTest_YoutubePremium${Font_Suffix}"
#
echo -e "\n ${Font_Yellow}Tiktok Region:${Font_Suffix}\t\t\t->\c"
BenchAPI_StreamingServiceUnlockTest_TiktokRegion
echo -n -e "\r ${Font_Yellow}Tiktok Region:${Font_Suffix}\t\t\t${Font_SkyBlue}$Result_StreamingServiceUnlockTest_TiktokRegion${Font_Suffix}"
#
echo -e "\n ${Font_Yellow}BBC iPlayer:${Font_Suffix}\t\t\t->\c"
BenchAPI_StreamingServiceUnlockTest_BBCiPlayer
echo -n -e "\r ${Font_Yellow}BBC iPlayer:${Font_Suffix}\t\t\t${Font_SkyBlue}$Result_StreamingServiceUnlockTest_BBCiPlayer${Font_Suffix}"
#
echo -e "\n ${Font_Yellow}NicoNico:${Font_Suffix}\t\t\t->\c"
BenchAPI_StreamingServiceUnlockTest_NicoVideo
echo -n -e "\r ${Font_Yellow}NicoNico:${Font_Suffix}\t\t\t${Font_SkyBlue}$Result_StreamingServiceUnlockTest_NicoVideo${Font_Suffix}"
#
echo -e "\n ${Font_Yellow}Princonne Re:dive Japan:${Font_Suffix}\t->\c"
BenchAPI_StreamingServiceUnlockTest_PriconneRediveJP
echo -n -e "\r ${Font_Yellow}Princonne Re:dive Japan:${Font_Suffix}\t${Font_SkyBlue}$Result_StreamingServiceUnlockTest_PriconneRediveJP${Font_Suffix}"
#
echo -e "\n ${Font_Yellow}Pretty Derby Japan:${Font_Suffix}\t\t->\c"
BenchAPI_StreamingServiceUnlockTest_UmamusumeJP
echo -n -e "\r ${Font_Yellow}Pretty Derby Japan:${Font_Suffix}\t\t${Font_SkyBlue}$Result_StreamingServiceUnlockTest_UmamusumeJP${Font_Suffix}"
#
echo -e "\n ${Font_Yellow}Kantai Collection Japan:${Font_Suffix}\t->\c"
BenchAPI_StreamingServiceUnlockTest_KancolleJP
echo -n -e "\r ${Font_Yellow}Kantai Collection Japan:${Font_Suffix}\t${Font_SkyBlue}$Result_StreamingServiceUnlockTest_KancolleJP${Font_Suffix}"
#
echo -e "\n ${Font_Yellow}Bahamut Anime:${Font_Suffix}\t\t\t->\c"
BenchAPI_StreamingServiceUnlockTest_BahamutAnime
echo -n -e "\r ${Font_Yellow}Bahamut Anime:${Font_Suffix}\t\t\t${Font_SkyBlue}$Result_StreamingServiceUnlockTest_BahamutAnime${Font_Suffix}"
#
echo -e "\n ${Font_Yellow}Bilibili (China Mainland):${Font_Suffix}\t->\c"
BenchAPI_StreamingServiceUnlockTest_BilibiliChinaMainland
echo -n -e "\r ${Font_Yellow}Bilibili (China Mainland):${Font_Suffix}\t${Font_SkyBlue}$Result_StreamingServiceUnlockTest_BilibiliChinaMainland${Font_Suffix}"
#
echo -e "\n ${Font_Yellow}Bilibili (China SAR&Taiwan):${Font_Suffix}\t->\c"
BenchAPI_StreamingServiceUnlockTest_BilibiliChinaSARTaiwan
echo -n -e "\r ${Font_Yellow}Bilibili (China SAR&Taiwan):${Font_Suffix}\t${Font_SkyBlue}$Result_StreamingServiceUnlockTest_BilibiliChinaSARTaiwan${Font_Suffix}"
#
echo -e "\n ${Font_Yellow}Bilibili (China Taiwan):${Font_Suffix}\t->\c"
BenchAPI_StreamingServiceUnlockTest_BilibiliChinaTaiwan
echo -n -e "\r ${Font_Yellow}Bilibili (China Taiwan):${Font_Suffix}\t${Font_SkyBlue}$Result_StreamingServiceUnlockTest_BilibiliChinaTaiwan${Font_Suffix}"
#
echo -e "\n ${Font_Yellow}Steam Price Currency:${Font_Suffix}\t\t->\c"
BenchAPI_StreamingServiceUnlockTest_SteamPriceCurrency
echo -n -e "\r ${Font_Yellow}Steam Price Currency:${Font_Suffix}\t\t${Font_SkyBlue}$Result_StreamingServiceUnlockTest_SteamPriceCurrency${Font_Suffix}"
#
echo -e ""
}
#
# -> 流媒体解锁测试模块 (Collector) - Netflix
function BenchAPI_StreamingServiceUnlockTest_Netflix() {
local res1 && res1=$(curl -fsL --user-agent "$GlobalVar_UA_WebBrowser" --max-time "$GlobalVar_CurlMaxTime" --write-out "%{http_code}" --output /dev/null "https://www.netflix.com/title/81215567" 2>&1)
case "$res1" in
404)
Result_StreamingServiceUnlockTest_Netflix="Netflix Only"
return 0
;;
200)
local res2 && res2="$(curl -fsL --user-agent "$GlobalVar_UA_WebBrowser" --max-time "$GlobalVar_CurlMaxTime" --write-out "%{redirect_url}" --output /dev/null "https://www.netflix.com/title/80018499" | cut -d '/' -f4 | cut -d '-' -f1 | tr "[:lower:]" "[:upper:]")"
[[ -z "$R_res2" ]] && Result_StreamingServiceUnlockTest_Netflix="Yes (GeoIP: US)" || Result_StreamingServiceUnlockTest_Netflix="Yes (GeoIP: $res2)"
return 0
;;
000)
Result_StreamingServiceUnlockTest_Netflix="FAIL (Network Connection Error)"
return 1
;;
*)
Result_StreamingServiceUnlockTest_Netflix="FAIL (Unexpected Result)"
return 1
;;
esac
}
#
# -> 流媒体解锁测试模块 (Collector) - HBO Now
function BenchAPI_StreamingServiceUnlockTest_HBONow() {
local res1 && res1="$(curl -fsL --user-agent "$GlobalVar_UA_WebBrowser" --max-time "$GlobalVar_CurlMaxTime" --write-out "%{url_effective}" --output /dev/null https://play.hbonow.com/ 2>&1)"
case "$res1" in
"https://play.hbonow.com")
Result_StreamingServiceUnlockTest_HBONow="Yes"
return 0
;;
"https://play.hbonow.com/")
Result_StreamingServiceUnlockTest_HBONow="Yes"
return 0
;;
"https://play.hbomax.com")
Result_StreamingServiceUnlockTest_HBONow="Yes"
return 0
;;
"https://play.hbomax.com/")
Result_StreamingServiceUnlockTest_HBONow="Yes"
return 0
;;
"http://hbogeo.cust.footprint.net/hbonow/geo.html")
Result_StreamingServiceUnlockTest_HBONow="No"
return 0
;;
"http://geocust.hbonow.com/hbonow/geo.html")
Result_StreamingServiceUnlockTest_HBONow="No"
return 0
;;
"curl"*)
Result_StreamingServiceUnlockTest_HBONow="FAIL (Network Connection Error)"
return 1
;;
*)
Result_StreamingServiceUnlockTest_HBONow="FAIL (Unexpected Result)"
return 1
;;
esac
}
#
# -> 流媒体解锁测试模块 (Collector) - Youtube Premium
function BenchAPI_StreamingServiceUnlockTest_YoutubePremium() {
local res1 && res1="$(curl -fsL --user-agent "$GlobalVar_UA_WebBrowser" --max-time "$GlobalVar_CurlMaxTime" https://www.youtube.com/red 2>&1)"
if [[ "$res1" == "curl"* ]]; then
Result_StreamingServiceUnlockTest_YoutubePremium="FAIL (Network Connection Error)"
return 1
fi
local res2 && res2="$(echo "$res1" | grep -oP '(?<="countryCode":").*?(?=")')"
if [ -n "$res2" ]; then
Result_StreamingServiceUnlockTest_YoutubePremium="Yes (GeoIP: $res2)"
return 0
fi
local res3 && res3="$(echo "$res1" | grep -o "Premium is not available in your country")"
if [ -n "$res3" ]; then
Result_StreamingServiceUnlockTest_YoutubePremium="No"
return 0
fi
Result_StreamingServiceUnlockTest_YoutubePremium="FAIL (Unexpected Result)"
return 1
}
#
# -> 流媒体解锁测试模块 (Collector) - Tiktok Region
function BenchAPI_StreamingServiceUnlockTest_TiktokRegion() {
local res1 && res1="$(curl -fsL --user-agent "$GlobalVar_UA_WebBrowser" --max-time "$GlobalVar_CurlMaxTime" https://www.tiktok.com/ 2>&1)"
if [[ "$res1" == "curl"* ]]; then
Result_StreamingServiceUnlockTest_TiktokRegion="FAIL (Network Connection Error)"
return 1
fi
local res2 && res2="$(echo "$res1" | grep -oP '(?<="\$region":").*?(?=")' | head -1)"
if [ -n "$res2" ]; then
Result_StreamingServiceUnlockTest_TiktokRegion="Yes"
return 0
else
Result_StreamingServiceUnlockTest_TiktokRegion="No"
return 0
fi
}
#
# -> 流媒体解锁测试模块 (Collector) - BBC iPlayer
function BenchAPI_StreamingServiceUnlockTest_BBCiPlayer() {
local res1 && res1="$(curl -fsL --user-agent "$GlobalVar_UA_WebBrowser" --max-time "$GlobalVar_CurlMaxTime" https://open.live.bbc.co.uk/mediaselector/6/select/version/2.0/mediaset/pc/vpid/bbc_one_london/format/json/jsfunc/JS_callbacks0 2>&1)"
if [[ "$res1" == "curl"* ]]; then
Result_StreamingServiceUnlockTest_BBCiPlayer="FAIL (Network Connection Error)"
return 1
fi
local res2 && res2="$(echo "$res2" | grep -o "geolocation")"
if [ "$res2" = "geolocation" ]; then
Result_StreamingServiceUnlockTest_BBCiPlayer="No"
return 0
else
Result_StreamingServiceUnlockTest_BBCiPlayer="Yes"
return 0
fi
}
#
# -> 流媒体解锁测试模块 (Collector) - NicoNico
function BenchAPI_StreamingServiceUnlockTest_NicoVideo() {
local res1 && res1="$(curl -fsL --user-agent "$GlobalVar_UA_WebBrowser" --max-time "$GlobalVar_CurlMaxTime" https://www.nicovideo.jp/watch/so23017073 2>&1)"
if [[ "$res1" == "curl"* ]]; then
Result_StreamingServiceUnlockTest_NicoVideo="FAIL (Network Connection Error)"
return 1
fi
local res2 && res2="$(echo "$res1" | grep -oP "(?<=<p class=\"fail-message\">).*(?=</p>)")"
if [ "$res2" = "この動画は投稿( アップロード )された地域と同じ地域からのみ視聴できます。" ]; then
Result_StreamingServiceUnlockTest_NicoVideo="No"
return 0
else
Result_StreamingServiceUnlockTest_NicoVideo="Yes"
return 0
fi
}
#
# -> 流媒体解锁测试模块 (Collector) - Princess Connect Re:Dive (JPN Server)
function BenchAPI_StreamingServiceUnlockTest_PriconneRediveJP() {
local res1 && res1="$(curl -fsL --user-agent "$GlobalVar_UA_UnityPlayer" --max-time "$GlobalVar_CurlMaxTime" --write-out "%{http_code}" --output /dev/null https://api-priconne-redive.cygames.jp/)"
if [[ "$res1" == "curl"* ]]; then
Result_StreamingServiceUnlockTest_PriconneRediveJP="FAIL (Network Connection Error)"
return 1
fi
case "$res1" in
404)
Result_StreamingServiceUnlockTest_PriconneRediveJP="Yes"
return 0
;;
403)
Result_StreamingServiceUnlockTest_PriconneRediveJP="No"
return 0
;;
000)
Result_StreamingServiceUnlockTest_PriconneRediveJP="FAIL (Network Connection Error)"
return 1
;;
*)
Result_StreamingServiceUnlockTest_PriconneRediveJP="FAIL (Unknown Result)"
return 1
;;
esac
}
#
# -> 流媒体解锁测试模块 (Collector) - Pretty Derby (JPN Server)
function BenchAPI_StreamingServiceUnlockTest_UmamusumeJP() {
local res1 && res1="$(curl -fsL --user-agent "$GlobalVar_UA_UnityPlayer" --max-time "$GlobalVar_CurlMaxTime" --write-out "%{http_code}" --output /dev/null https://api-umamusume.cygames.jp/)"
if [[ "$res1" == "curl"* ]]; then
Result_StreamingServiceUnlockTest_UmamusumeJP="FAIL (Network Connection Error)"
return 1
fi
case "$res1" in
404)
local f1 && f1="1"
;;
403)
local f1 && f1="0"
;;
*)
Result_StreamingServiceUnlockTest_UmamusumeJP="FAIL (Unexpected Result)"
return 1
;;
esac
local res2 && res2="$(curl -fsL --user-agent "${GlobalVar_UA_UnityPlayer}" --max-time 10 --write-out "%{http_code}" --output /dev/null https://api-umamusume.cygames.jp/umamusume/tool/pre_signup)"
if [[ "$res2" == "curl"* ]]; then
Result_StreamingServiceUnlockTest_UmamusumeJP="FAIL (Network Connection Error)"
return 1
fi
case "$res2" in
500)
local f2 && f2="1"
;;
403)
local f2 && f2="1"
;;
*)
Result_StreamingServiceUnlockTest_UmamusumeJP="FAIL (Unexpected Result)"
return 1
;;
esac
if [ "$f1" = "1" ] && [ "$f2" = "1" ]; then
Result_StreamingServiceUnlockTest_UmamusumeJP="Yes"
return 0
elif [ "$f1" = "1" ] && [ "$f2" = "0" ]; then
Result_StreamingServiceUnlockTest_UmamusumeJP="Game Only (Cannot Register)"
return 0
else
Result_StreamingServiceUnlockTest_UmamusumeJP="No"
return 0
fi
}
#
# -> 流媒体解锁测试模块 (Collector) - Kantai Collection (JPN Server)
function BenchAPI_StreamingServiceUnlockTest_KancolleJP() {
local res1 && res1="$(curl -fsL --user-agent "$GlobalVar_UA_WebBrowser" --max-time "$GlobalVar_CurlMaxTime" --write-out "%{http_code}" --output /dev/null http://203.104.209.7/kcscontents/)"
if [[ "$res1" == "curl"* ]]; then
Result_StreamingServiceUnlockTest_KancolleJP="FAIL (Network Connection Error)"
return 1
fi
case $res1 in
200)
Result_StreamingServiceUnlockTest_KancolleJP="Yes"
return 0
;;
403)
Result_StreamingServiceUnlockTest_KancolleJP="No"
return 0
;;
000)
Result_StreamingServiceUnlockTest_KancolleJP="FAIL (Network Connection Error)"
return 1
;;
*)
Result_StreamingServiceUnlockTest_KancolleJP="FAIL (Unexpected Result)"
return 1
;;
esac
}
#
# -> 流媒体解锁测试模块 (Collector) - 巴哈姆特動畫瘋
function BenchAPI_StreamingServiceUnlockTest_BahamutAnime() {
local res1 && res1="$(curl -fsL --user-agent "$GlobalVar_UA_WebBrowser" --max-time "$GlobalVar_CurlMaxTime" 'https://ani.gamer.com.tw/ajax/token.php?adID=89422&sn=14667' 2>&1)"
if [[ "$res1" == "curl"* ]]; then
Result_StreamingServiceUnlockTest_BahamutAnime="FAIL (Network Connection Error)"
return 1
fi
local res2 && res2="$(BenchExec_PharseJSON "$res1" "error.code")"
if [ "$res2" = "1011" ]; then
Result_StreamingServiceUnlockTest_BahamutAnime="No"
return 0
fi
local res3 && res3="$(BenchExec_PharseJSON "$res1" "animeSn")"
if [ -n "$res3" ]; then
Result_StreamingServiceUnlockTest_BahamutAnime="Yes"
return 0
else
Result_StreamingServiceUnlockTest_BahamutAnime="No"
return 0
fi
}
#
# -> 流媒体解锁测试模块 (Collector) - 哔哩哔哩中国大陆地区限定
function BenchAPI_StreamingServiceUnlockTest_BilibiliChinaMainland() {
local r_session && r_session="$(head -n 32 /dev/urandom | md5sum | head -c 32)"
local res1 && res1="$(curl -fsL --user-agent "$GlobalVar_UA_WebBrowser" --max-time "$GlobalVar_CurlMaxTime" "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=$r_session&module=bangumi" 2>&1)"
if [[ "$res1" == "curl"* ]]; then
Result_StreamingServiceUnlockTest_BilibiliChinaMainland="FAIL (Network Connection Error)"
return 1
fi
local res2 && res2="$(BenchExec_PharseJSON "$res1" ".code")"
case $res2 in
0)
Result_StreamingServiceUnlockTest_BilibiliChinaMainland="Yes"
return 0
;;
-10403)
Result_StreamingServiceUnlockTest_BilibiliChinaMainland="No"
return 0
;;
*)
Result_StreamingServiceUnlockTest_BilibiliChinaMainland="FAIL (Unexpected Result)"
return 1
;;
esac
}
# -> 流媒体解锁测试模块 (Collector) - 哔哩哔哩中国港澳台地区限定
function BenchAPI_StreamingServiceUnlockTest_BilibiliChinaSARTaiwan() {
local r_session && r_session="$(head -n 32 /dev/urandom | md5sum | head -c 32)"
local res1 && res1="$(curl -fsL --user-agent "$GlobalVar_UA_WebBrowser" --max-time "$GlobalVar_CurlMaxTime" "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=$r_session&module=bangumi" 2>&1)"
if [[ "$res1" == "curl"* ]]; then
Result_StreamingServiceUnlockTest_BilibiliChinaSARTaiwan="FAIL (Network Connection Error)"
return 1
fi
local res2 && res2="$(BenchExec_PharseJSON "$res1" ".code")"
case $res2 in
0)
Result_StreamingServiceUnlockTest_BilibiliChinaSARTaiwan="Yes"
return 0
;;
-10403)
Result_StreamingServiceUnlockTest_BilibiliChinaSARTaiwan="No"
return 0
;;
*)
Result_StreamingServiceUnlockTest_BilibiliChinaSARTaiwan="FAIL (Unexpected Result)"
return 1
;;
esac
}
# -> 流媒体解锁测试模块 (Collector) - 哔哩哔哩中国台湾地区限定
function BenchAPI_StreamingServiceUnlockTest_BilibiliChinaTaiwan() {
local r_session && r_session="$(head -n 32 /dev/urandom | md5sum | head -c 32)"
local res1 && res1="$(curl -fsL --user-agent "${GlobalVar_UA_WebBrowser}" --max-time "$GlobalVar_CurlMaxTime" "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=$r_session&module=bangumi" 2>&1)"
if [[ "$res1" == "curl"* ]]; then
Result_StreamingServiceUnlockTest_BilibiliChinaTaiwan="FAIL (Network Connection Error)"
return 1
fi
local res2 && res2="$(BenchExec_PharseJSON "$res1" ".code")"
case $res2 in
0)
Result_StreamingServiceUnlockTest_BilibiliChinaTaiwan="Yes"
return 0
;;
-10403)
Result_StreamingServiceUnlockTest_BilibiliChinaTaiwan="No"
return 0
;;
*)
Result_StreamingServiceUnlockTest_BilibiliChinaTaiwan="FAIL (Unexpected Result)"
return 1
;;
esac
}
# -> 流媒体解锁测试模块 (Collector) - Steam Price Currency
function BenchAPI_StreamingServiceUnlockTest_SteamPriceCurrency() {
local res1 && res1="$(curl -fsL --user-agent "$GlobalVar_UA_WebBrowser" --max-time "$GlobalVar_CurlMaxTime" https://store.steampowered.com/app/20 2>&1)"
if [[ "$res1" == "curl"* ]]; then
Result_StreamingServiceUnlockTest_SteamPriceCurrency="FAIL (Network Connection Error)"
return 1
fi
local res2 && res2="$(echo "$res1" | grep 'priceCurrency' | grep -oP '(?<=content\=").*?(?=")')"
if [ -n "$res2" ]; then
Result_StreamingServiceUnlockTest_SteamPriceCurrency="$res2"
return 0
fi
Result_StreamingServiceUnlockTest_SteamPriceCurrency="FAIL (Unexpected Result)"
return 1
}
# ===========================================================================
# -> CPU 性能测试模块 (Entrypoint) -> 执行 (快速模式)
function BenchFunc_PerformanceTest_CPU_RunTest_Fast() {
BenchAPI_PerformanceTest_CPU "fast" "5" "1"
}
# -> CPU 性能测试模块 (Entrypoint) -> 执行 (完整模式)
function BenchFunc_PerformanceTest_CPU_RunTest_Full() {
BenchAPI_PerformanceTest_CPU "full" "30" "3"
}
# -> CPU 性能测试模块 (Executor) -> 执行核心代码
function BenchExec_Sysbench_CPU() {
local cc && cc="1" # Count Current
local ct && ct="$3" # Count Total
local sc && sc="0" # Score Current
local st && st="0" # Score Total
while [ "$cc" -le "$ct" ]; do
local rr && rr="$(sysbench --num-threads="$1" --cpu-max-prime=10000 --events=1000000 --time="$2" cpu run 2>&1)"
local sc && sc="$(echo "$rr" | grep "events per second:" | grep -oE "[0-9]+\.[0-9]+")"
local st && st="$(echo "$st $sc" | awk '{printf "%.2f",$1+$2}')"
((cc = cc + 1))
rr=""
sc="0"
done
local sa && sa="$(echo "$st $ct" | awk '{printf "%.2f",$1/$2}')" # Score Average (=Final Score)
echo -n "$sa"
sleep 1
return 0
}
# -> CPU 性能测试模块 (Collector) -> 运行测试
function BenchAPI_PerformanceTest_CPU() {
if [ "$1" = "fast" ]; then
echo -e "\n ${Font_Yellow}-> CPU Performance Test (Fast mode, $3-Pass @ $2sec)${Font_Suffix}\n"
Result_PerformanceTest_CPU_BenchTitle=" -> CPU Performance Test (Fast mode, $3-Pass @ $2sec)"
elif [ "$1" = "full" ]; then
echo -e "\n ${Font_Yellow}-> CPU Performance Test (Full mode, $3-Pass @ $2sec)${Font_Suffix}\n"
Result_PerformanceTest_CPU_BenchTitle=" -> CPU Performance Test (Full mode, $3-Pass @ $2sec)"
else
echo -e "${Msg_Error} BenchAPI_PerformanceTest_CPU(): invalid params ($1), please check parameter!"
exit 1
fi
echo -e " ${Font_Yellow}1 Thread(s) Test:${Font_Suffix}\t\t->\c"