-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
ssr.sh
1482 lines (1471 loc) · 54.9 KB
/
ssr.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
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#=================================================
# System Required: CentOS 6/Debian/Ubuntu 14.04+
# Description: Install the ShadowsocksR server
# Version: 1.2.5
# Author: Toyo
# Blog: https://doub.io/ss-jc42/
#=================================================
#ssr_pid="/var/run/shadowsocks.pid"
ssr_file="/etc/shadowsocksr"
ssr_ss_file="/etc/shadowsocksr/shadowsocks/"
config_file="/etc/shadowsocksr/config.json"
config_user_file="/etc/shadowsocksr/user-config.json"
Libsodiumr_file="/root/libsodium"
Libsodiumr_ver="1.0.11"
auto_restart_cron="auto_restart_cron.sh"
Separator_1="——————————————————————————————"
#检查系统
check_sys(){
if [[ -f /etc/redhat-release ]]; then
release="centos"
elif cat /etc/issue | grep -q -E -i "debian"; then
release="debian"
elif cat /etc/issue | grep -q -E -i "ubuntu"; then
release="ubuntu"
elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
elif cat /proc/version | grep -q -E -i "debian"; then
release="debian"
elif cat /proc/version | grep -q -E -i "ubuntu"; then
release="ubuntu"
elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then
release="centos"
fi
#bit=`uname -m`
}
SSR_install_status(){
[[ ! -e $config_user_file ]] && echo -e "\033[41;37m [错误] \033[0m 没有发现安装ShadowsocksR,请检查 !" && exit 1
}
#获取IP
getIP(){
ip=`curl -m 10 -s "ipinfo.io" | jq '.ip' | sed 's/^.//;s/.$//'`
[[ -z "$ip" ]] && ip="VPS_IP"
}
#获取用户账号信息
getUser(){
port=`jq '.server_port' ${config_user_file}`
password=`jq '.password' ${config_user_file} | sed 's/^.//;s/.$//'`
method=`jq '.method' ${config_user_file} | sed 's/^.//;s/.$//'`
protocol=`jq '.protocol' ${config_user_file} | sed 's/^.//;s/.$//'`
obfs=`jq '.obfs' ${config_user_file} | sed 's/^.//;s/.$//'`
protocol_param=`jq '.protocol_param' ${config_user_file} | sed 's/^.//;s/.$//'`
speed_limit_per_con=`jq '.speed_limit_per_con' ${config_user_file}`
speed_limit_per_user=`jq '.speed_limit_per_user' ${config_user_file}`
}
# 设置 端口和密码
set_port_pass(){
#设置端口
while true
do
echo -e "请输入ShadowsocksR账号的 端口 [1-65535]:"
read -p "(默认端口: 2333):" ssport
[[ -z "$ssport" ]] && ssport="2333"
expr ${ssport} + 0 &>/dev/null
if [[ $? -eq 0 ]]; then
if [[ ${ssport} -ge 1 ]] && [[ ${ssport} -le 65535 ]]; then
echo && echo ${Separator_1} && echo -e " 端口 : \033[32m${ssport}\033[0m" && echo ${Separator_1} && echo
break
else
echo "输入错误,请输入正确的数字 !"
fi
else
echo "输入错误,请输入正确的数字 !"
fi
done
#设置密码
echo "请输入ShadowsocksR账号的 密码:"
read -p "(默认密码: doub.io):" sspwd
[[ -z "${sspwd}" ]] && sspwd="doub.io"
echo && echo ${Separator_1} && echo -e " 密码 : \033[32m${sspwd}\033[0m" && echo ${Separator_1} && echo
}
# 设置 加密方式、协议和混淆等
set_others(){
#设置加密方式
echo "请输入数字 来选择ShadowsocksR账号的 加密方式:"
echo " 1. rc4-md5"
echo " 2. aes-128-ctr"
echo " 3. aes-256-ctr"
echo " 4. aes-256-cfb"
echo " 5. aes-256-cfb8"
echo " 6. camellia-256-cfb"
echo " 7. chacha20"
echo " 8. chacha20-ietf"
echo -e "\033[32m 注意: \033[0mchacha20*等加密方式 需要安装 libsodium 支持库,否则会启动失败!"
echo
read -p "(默认加密方式: 2. aes-128-ctr):" ssmethod
[[ -z "${ssmethod}" ]] && ssmethod="2"
if [[ ${ssmethod} == "1" ]]; then
ssmethod="rc4-md5"
elif [[ ${ssmethod} == "2" ]]; then
ssmethod="aes-128-ctr"
elif [[ ${ssmethod} == "3" ]]; then
ssmethod="aes-256-ctr"
elif [[ ${ssmethod} == "4" ]]; then
ssmethod="aes-256-cfb"
elif [[ ${ssmethod} == "5" ]]; then
ssmethod="aes-256-cfb8"
elif [[ ${ssmethod} == "6" ]]; then
ssmethod="camellia-256-cfb"
elif [[ ${ssmethod} == "7" ]]; then
ssmethod="chacha20"
elif [[ ${ssmethod} == "8" ]]; then
ssmethod="chacha20-ietf"
else
ssmethod="aes-128-ctr"
fi
echo && echo ${Separator_1} && echo -e " 加密方式 : \033[32m${ssmethod}\033[0m" && echo ${Separator_1} && echo
#设置协议
echo "请输入数字 来选择ShadowsocksR账号的 协议( auth_aes128_* 以后的协议不再支持 兼容原版 ):"
echo " 1. origin"
echo " 2. auth_sha1_v4"
echo " 3. auth_aes128_md5"
echo " 4. auth_aes128_sha1"
echo
read -p "(默认协议: 2. auth_sha1_v4):" ssprotocol
[[ -z "${ssprotocol}" ]] && ssprotocol="2"
if [[ ${ssprotocol} == "1" ]]; then
ssprotocol="origin"
elif [[ ${ssprotocol} == "2" ]]; then
ssprotocol="auth_sha1_v4"
elif [[ ${ssprotocol} == "3" ]]; then
ssprotocol="auth_aes128_md5"
elif [[ ${ssprotocol} == "4" ]]; then
ssprotocol="auth_aes128_sha1"
else
ssprotocol="auth_sha1_v4"
fi
echo && echo ${Separator_1} && echo -e " 协议 : \033[32m${ssprotocol}\033[0m" && echo ${Separator_1} && echo
#设置混淆
echo "请输入数字 来选择ShadowsocksR账号的 混淆:"
echo " 1. plain"
echo " 2. http_simple"
echo " 3. http_post"
echo " 4. random_head"
echo " 5. tls1.2_ticket_auth"
echo
read -p "(默认混淆: 5. tls1.2_ticket_auth):" ssobfs
[[ -z "${ssobfs}" ]] && ssobfs="5"
if [[ ${ssobfs} == "1" ]]; then
ssobfs="plain"
elif [[ ${ssobfs} == "2" ]]; then
ssobfs="http_simple"
elif [[ ${ssobfs} == "3" ]]; then
ssobfs="http_post"
elif [[ ${ssobfs} == "4" ]]; then
ssobfs="random_head"
elif [[ ${ssobfs} == "5" ]]; then
ssobfs="tls1.2_ticket_auth"
else
ssobfs="tls1.2_ticket_auth"
fi
echo && echo ${Separator_1} && echo -e " 混淆 : \033[32m${ssobfs}\033[0m" && echo ${Separator_1} && echo
#询问是否设置 混淆 兼容原版
if [[ ${ssprotocol} != "origin" ]]; then
if [[ ${ssobfs} != "plain" ]]; then
if [[ ${ssprotocol} == "verify_sha1" ]] || [[ ${ssprotocol} == "auth_sha1_v2" ]] || [[ ${ssprotocol} == "auth_sha1_v4" ]]; then
read -p "是否设置 协议/混淆 兼容原版 ( _compatible )? [Y/n] :" yn1
[[ -z "${yn1}" ]] && yn1="y"
[[ $yn1 == [Yy] ]] && ssobfs=${ssobfs}"_compatible" && ssprotocol=${ssprotocol}"_compatible"
else
read -p "是否设置 混淆 兼容原版 ( _compatible )? [Y/n] :" yn1
[[ -z "${yn1}" ]] && yn1="y"
[[ $yn1 == [Yy] ]] && ssobfs=${ssobfs}"_compatible"
fi
else
if [[ ${ssprotocol} == "verify_sha1" ]] || [[ ${ssprotocol} == "auth_sha1_v2" ]] || [[ ${ssprotocol} == "auth_sha1_v4" ]]; then
read -p "是否设置 协议 兼容原版 ( _compatible )? [Y/n] :" yn1
[[ -z "${yn1}" ]] && yn1="y"
[[ $yn1 == [Yy] ]] && ssprotocol=${ssprotocol}"_compatible"
fi
fi
else
if [[ ${ssobfs} != "plain" ]]; then
read -p "是否设置 混淆 兼容原版 ( _compatible )? [Y/n] :" yn1
[[ -z "${yn1}" ]] && yn1="y"
[[ $yn1 == [Yy] ]] && ssobfs=${ssobfs}"_compatible"
fi
fi
if [[ ${ssprotocol} != "origin" ]]; then
while true
do
echo
echo -e "请输入 ShadowsocksR账号欲限制的设备数 (\033[32m auth_* 系列协议 不兼容原版才有效 \033[0m)"
echo -e "\033[32m 注意: \033[0m该设备数限制,指的是每个端口同一时间能链接的客户端数量(多端口模式,每个端口都是独立计算)。"
read -p "(回车 默认无限):" ssprotocol_param
[[ -z "$ssprotocol_param" ]] && ssprotocol_param="" && break
expr ${ssprotocol_param} + 0 &>/dev/null
if [[ $? -eq 0 ]]; then
if [[ ${ssprotocol_param} -ge 1 ]] && [[ ${ssprotocol_param} -le 99999 ]]; then
echo && echo ${Separator_1} && echo -e " 设备数 : \033[32m${ssprotocol_param}\033[0m" && echo ${Separator_1} && echo
break
else
echo "输入错误,请输入正确的数字 !"
fi
else
echo "输入错误,请输入正确的数字 !"
fi
done
fi
# 设置单线程限速
while true
do
echo
echo -e "请输入 你要设置的每个端口 单线程 限速上限(单位:KB/S)"
echo -e "\033[32m 注意: \033[0m这个指的是,每个端口 单线程的限速上限,多线程即无效。"
read -p "(回车 默认无限):" ssspeed_limit_per_con
[[ -z "$ssspeed_limit_per_con" ]] && ssspeed_limit_per_con=0 && break
expr ${ssspeed_limit_per_con} + 0 &>/dev/null
if [[ $? -eq 0 ]]; then
if [[ ${ssspeed_limit_per_con} -ge 1 ]] && [[ ${ssspeed_limit_per_con} -le 99999 ]]; then
echo && echo ${Separator_1} && echo -e " 单端口单线程 : \033[32m${ssspeed_limit_per_con} KB/S\033[0m" && echo ${Separator_1} && echo
break
else
echo "输入错误,请输入正确的数字 !"
fi
else
echo "输入错误,请输入正确的数字 !"
fi
done
# 设置端口总限速
while true
do
echo
echo -e "请输入 你要设置的每个端口 总速度 限速上限(单位:KB/S)"
echo -e "\033[32m 注意: \033[0m这个指的是,每个端口 总速度 限速上限,单个端口整体限速。"
read -p "(回车 默认无限):" ssspeed_limit_per_user
[[ -z "$ssspeed_limit_per_user" ]] && ssspeed_limit_per_user=0 && break
expr ${ssspeed_limit_per_user} + 0 &>/dev/null
if [[ $? -eq 0 ]]; then
if [[ ${ssspeed_limit_per_user} -ge 1 ]] && [[ ${ssspeed_limit_per_user} -le 99999 ]]; then
echo && echo ${Separator_1} && echo -e " 单端口总限速 : \033[32m${ssspeed_limit_per_user} KB/S\033[0m" && echo ${Separator_1} && echo
break
else
echo "输入错误,请输入正确的数字 !"
fi
else
echo "输入错误,请输入正确的数字 !"
fi
done
}
#设置用户账号信息
setUser(){
set_port_pass
set_others
#最后确认
[[ "${ssprotocol_param}" == "" ]] && ssprotocol_param="0(无限)"
echo && echo ${Separator_1}
echo " 请检查Shadowsocks账号配置是否有误 !" && echo
echo -e " 端口\t : \033[32m${ssport}\033[0m"
echo -e " 密码\t : \033[32m${sspwd}\033[0m"
echo -e " 加密\t : \033[32m${ssmethod}\033[0m"
echo -e " 协议\t : \033[32m${ssprotocol}\033[0m"
echo -e " 混淆\t : \033[32m${ssobfs} \033[0m"
echo -e " 设备数限制 : \033[32m${ssprotocol_param}\033[0m"
echo -e " 单线程限速 : \033[32m${ssspeed_limit_per_con} KB/S\033[0m"
echo -e " 端口总限速 : \033[32m${ssspeed_limit_per_user} KB/S\033[0m"
echo ${Separator_1} && echo
read -p "请按任意键继续,如有配置错误请使用 Ctrl+C 退出。" var
[[ "${ssprotocol_param}" = "0(无限)" ]] && ssprotocol_param=""
}
ss_link_qr(){
SSbase64=`echo -n "${method}:${user_password}@${ip}:${user_port}" | base64 | sed ':a;N;s/\n/ /g;ta' | sed 's/ //g'`
SSurl="ss://"${SSbase64}
SSQRcode="http://pan.baidu.com/share/qrcode?w=300&h=300&url="${SSurl}
ss_link=" SS 链接 : \033[32m${SSurl}\033[0m \n SS 二维码 : \033[32m${SSQRcode}\033[0m"
}
ssr_link_qr(){
SSRprotocol=`echo ${protocol} | sed 's/_compatible//g'`
SSRobfs=`echo ${obfs} | sed 's/_compatible//g'`
SSRPWDbase64=`echo -n "${password}" | base64 | sed ':a;N;s/\n/ /g;ta' | sed 's/ //g'`
SSRbase64=`echo -n "${ip}:${port}:${SSRprotocol}:${method}:${SSRobfs}:${SSRPWDbase64}" | base64 | sed ':a;N;s/\n/ /g;ta' | sed 's/ //g'`
SSRurl="ssr://"${SSRbase64}
SSRQRcode="http://pan.baidu.com/share/qrcode?w=300&h=300&url="${SSRurl}
ssr_link=" SSR 链接 : \033[32m${SSRurl}\033[0m \n SSR 二维码 : \033[32m${SSRQRcode}\033[0m \n "
}
#显示用户账号信息
viewUser(){
SSR_install_status
PID=`ps -ef |grep -v grep | grep server.py |awk '{print $2}'`
if [[ -z "${PID}" ]]; then
ssr_status="\033[41;37m 当前状态: \033[0m ShadowsocksR 没有运行!"
else
ssr_status="\033[42;37m 当前状态: \033[0m ShadowsocksR 正在运行!"
fi
getIP
now_mode=`jq '.port_password' ${config_user_file}`
if [[ "${now_mode}" = "null" ]]; then
getUser
SSprotocol=`echo ${protocol} | awk -F "_" '{print $NF}'`
SSobfs=`echo ${obfs} | awk -F "_" '{print $NF}'`
if [[ ${protocol} = "origin" ]]; then
if [[ ${obfs} = "plain" ]]; then
ss_link_qr
ssr_link=""
else
if [[ ${SSobfs} != "compatible" ]]; then
ss_link=""
else
ss_link_qr
fi
fi
else
if [[ ${SSprotocol} != "compatible" ]]; then
ss_link=""
else
if [[ ${SSobfs} != "compatible" ]]; then
if [[ ${SSobfs} = "plain" ]]; then
ss_link_qr
else
ss_link=""
fi
else
ss_link_qr
fi
fi
fi
ssr_link_qr
[[ -z ${protocol_param} ]] && protocol_param="0(无限)"
clear
echo "==================================================="
echo
echo -e " 你的ShadowsocksR 账号配置 : "
echo
echo -e " I P\t : \033[32m${ip}\033[0m"
echo -e " 端口\t : \033[32m${port}\033[0m"
echo -e " 密码\t : \033[32m${password}\033[0m"
echo -e " 加密\t : \033[32m${method}\033[0m"
echo -e " 协议\t : \033[32m${protocol}\033[0m"
echo -e " 混淆\t : \033[32m${obfs}\033[0m"
echo -e " 设备数限制 : \033[32m${protocol_param}\033[0m"
echo -e " 单线程限速 : \033[32m${speed_limit_per_con} KB/S\033[0m"
echo -e " 端口总限速 : \033[32m${speed_limit_per_user} KB/S\033[0m"
echo -e "${ss_link}"
echo -e "${ssr_link}"
echo -e "\033[42;37m 提示: \033[0m"
echo -e " 浏览器中,打开二维码链接,就可以看到二维码图片。"
echo -e " 协议和混淆后面的[ _compatible ],指的是兼容原版Shadowsocks协议/混淆。"
echo
echo -e ${ssr_status}
echo
echo "==================================================="
else
getUser
[[ -z ${protocol_param} ]] && protocol_param="0(无限)"
clear
echo "==================================================="
echo
echo -e " 你的ShadowsocksR 账号配置 : "
echo
echo -e " I P\t : \033[32m${ip}\033[0m"
echo -e " 加密\t : \033[32m${method}\033[0m"
echo -e " 协议\t : \033[32m${protocol}\033[0m"
echo -e " 混淆\t : \033[32m${obfs}\033[0m"
echo -e " 设备数限制 : \033[32m${protocol_param}\033[0m"
echo -e " 单线程限速 : \033[32m${speed_limit_per_con} KB/S\033[0m"
echo -e " 端口总限速 : \033[32m${speed_limit_per_user} KB/S\033[0m"
echo
user_total=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | wc -l`
[[ ${socat_total} = "0" ]] && echo -e "\033[41;37m [错误] \033[0m 没有发现 多端口用户,请检查 !" && exit 1
user_id=0
check_sys
if [[ ${release} = "centos" ]]; then
for((integer = 1; integer <= ${user_total}; integer++))
do
user_port=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $1}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
user_password=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $2}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
user_id=$[$user_id+1]
SSprotocol=`echo ${protocol} | awk -F "_" '{print $NF}'`
SSobfs=`echo ${obfs} | awk -F "_" '{print $NF}'`
if [[ ${protocol} = "origin" ]]; then
if [[ ${obfs} = "plain" ]]; then
ss_link_qr
ssr_link=""
else
if [[ ${SSobfs} != "compatible" ]]; then
ss_link=""
else
ss_link_qr
fi
fi
else
if [[ ${SSprotocol} != "compatible" ]]; then
ss_link=""
else
if [[ ${SSobfs} != "compatible" ]]; then
if [[ ${SSobfs} = "plain" ]]; then
ss_link_qr
else
ss_link=""
fi
else
ss_link_qr
fi
fi
fi
ssr_link_qr
echo -e " ——————————\033[42;37m 用户 ${user_id} \033[0m ——————————"
echo -e " 端口\t : \033[32m${user_port}\033[0m"
echo -e " 密码\t : \033[32m${user_password}\033[0m"
echo -e "${ss_link}"
echo -e "${ssr_link}"
done
else
for((integer = ${user_total}; integer >= 1; integer--))
do
user_port=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $1}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
user_password=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $2}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
user_id=$[$user_id+1]
SSprotocol=`echo ${protocol} | awk -F "_" '{print $NF}'`
SSobfs=`echo ${obfs} | awk -F "_" '{print $NF}'`
if [[ ${protocol} = "origin" ]]; then
if [[ ${obfs} = "plain" ]]; then
ss_link_qr
ssr_link=""
else
if [[ ${SSobfs} != "compatible" ]]; then
ss_link=""
else
ss_link_qr
fi
fi
else
if [[ ${SSprotocol} != "compatible" ]]; then
ss_link=""
else
if [[ ${SSobfs} != "compatible" ]]; then
if [[ ${SSobfs} = "plain" ]]; then
ss_link_qr
else
ss_link=""
fi
else
ss_link_qr
fi
fi
fi
ssr_link_qr
echo -e " —————————— \033[42;37m 用户 ${user_id} \033[0m ——————————"
echo -e " 端口\t : \033[32m${user_port}\033[0m"
echo -e " 密码\t : \033[32m${user_password}\033[0m"
echo -e "${ss_link}"
echo -e "${ssr_link}"
done
fi
echo -e "\033[42;37m 提示: \033[0m"
echo -e " 浏览器中,打开二维码链接,就可以看到二维码图片。"
echo -e " 协议和混淆后面的[ _compatible ],指的是兼容原版Shadowsocks协议/混淆。"
echo
echo -e ${ssr_status}
echo
echo "==================================================="
fi
}
debian_apt(){
apt-get update
apt-get install -y python-pip python-m2crypto curl unzip vim git gcc build-essential make
}
centos_yum(){
yum update
yum install -y python-pip python-m2crypto curl unzip vim git gcc make
}
JQ_install(){
JQ_ver=`jq -V`
if [[ -z ${JQ_ver} ]]; then
#wget --no-check-certificate -N "https://softs.pw/Bash/other/jq-1.5.tar.gz"
wget --no-check-certificate -N "https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/other/jq-1.5.tar.gz"
tar -xzf jq-1.5.tar.gz && cd jq-1.5
./configure --disable-maintainer-mode && make && make install
ldconfig
cd .. && rm -rf jq-1.5.tar.gz && rm -rf jq-1.5
JQ_ver=`jq -V`
[[ -z ${JQ_ver} ]]&& echo -e "\033[41;37m [错误] \033[0m JSON解析器 JQ 安装失败 !" && exit 1
echo -e "\033[42;37m [信息] \033[0m JSON解析器 JQ 安装完成,继续..."
else
echo -e "\033[42;37m [信息] \033[0m 检测到 JSON解析器 JQ 已安装,继续..."
fi
}
rc.local_ss_set(){
#添加开机启动
if [[ ${release} = "centos" ]]; then
chmod +x /etc/rc.d/rc.local
sed -i '/cd \/etc\/shadowsocksr\/shadowsocks\//d' /etc/rc.d/rc.local
sed -i '/nohup python server.py a >> ssserver.log 2>&1 &/d' /etc/rc.d/rc.local
echo -e "cd ${ssr_ss_file}" >> /etc/rc.d/rc.local
echo -e "nohup python server.py a >> ssserver.log 2>&1 &" >> /etc/rc.d/rc.local
else
chmod +x /etc/rc.local
sed -i '$d' /etc/rc.local
sed -i '/cd \/etc\/shadowsocksr\/shadowsocks\//d' /etc/rc.local
sed -i '/nohup python server.py a >> ssserver.log 2>&1 &/d' /etc/rc.local
echo -e "cd ${ssr_ss_file}" >> /etc/rc.local
echo -e "nohup python server.py a >> ssserver.log 2>&1 &" >> /etc/rc.local
echo -e "exit 0" >> /etc/rc.local
fi
}
rc.local_ss_del(){
if [[ ${release} = "centos" ]]; then
sed -i '/cd \/etc\/shadowsocksr\/shadowsocks\//d' /etc/rc.d/rc.local
sed -i '/nohup python server.py a >> ssserver.log 2>&1 &/d' /etc/rc.d/rc.local
else
sed -i '/cd \/etc\/shadowsocksr\/shadowsocks\//d' /etc/rc.local
sed -i '/nohup python server.py a >> ssserver.log 2>&1 &/d' /etc/rc.local
fi
}
rc.local_serverspeed_set(){
#添加开机启动
if [[ ${release} = "centos" ]]; then
chmod +x /etc/rc.d/rc.local
sed -i '/\/serverspeeder\/bin\/serverSpeeder.sh start/d' /etc/rc.d/rc.local
echo -e "/serverspeeder/bin/serverSpeeder.sh start" >> /etc/rc.d/rc.local
else
chmod +x /etc/rc.local
sed -i '$d' /etc/rc.local
sed -i '/\/serverspeeder\/bin\/serverSpeeder.sh start/d' /etc/rc.local
echo -e "/serverspeeder/bin/serverSpeeder.sh start" >> /etc/rc.local
echo -e "exit 0" >> /etc/rc.local
fi
}
rc.local_serverspeed_del(){
if [[ ${release} = "centos" ]]; then
sed -i '/\/serverspeeder\/bin\/serverSpeeder.sh start/d' /etc/rc.d/rc.local
else
sed -i '/\/serverspeeder\/bin\/serverSpeeder.sh start/d' /etc/rc.local
fi
}
iptables_add(){
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport ${ssport} -j ACCEPT
iptables -I INPUT -m state --state NEW -m udp -p udp --dport ${ssport} -j ACCEPT
}
iptables_del(){
iptables -D INPUT -m state --state NEW -m tcp -p tcp --dport ${port} -j ACCEPT
iptables -D INPUT -m state --state NEW -m udp -p udp --dport ${port} -j ACCEPT
}
iptables_set(){
#删除旧端口的防火墙规则,添加新端口的规则
iptables_del
iptables_add
}
set_config_port_pass(){
sed -i 's/"server_port": '$(echo ${port})'/"server_port": '$(echo ${ssport})'/g' ${config_user_file}
sed -i 's/"password": "'$(echo ${password})'"/"password": "'$(echo ${sspwd})'"/g' ${config_user_file}
}
set_config_method_obfs_protocol(){
sed -i 's/"method": "'$(echo ${method})'"/"method": "'$(echo ${ssmethod})'"/g' ${config_user_file}
sed -i 's/"obfs": "'$(echo ${obfs})'"/"obfs": "'$(echo ${ssobfs})'"/g' ${config_user_file}
sed -i 's/"protocol": "'$(echo ${protocol})'"/"protocol": "'$(echo ${ssprotocol})'"/g' ${config_user_file}
}
set_config_protocol_param(){
sed -i 's/"protocol_param": "'$(echo ${protocol_param})'"/"protocol_param": "'$(echo ${ssprotocol_param})'"/g' ${config_user_file}
}
set_config_speed_limit_per(){
sed -i 's/"speed_limit_per_con": '$(echo ${speed_limit_per_con})'/"speed_limit_per_con": '$(echo ${ssspeed_limit_per_con})'/g' ${config_user_file}
sed -i 's/"speed_limit_per_user": '$(echo ${speed_limit_per_user})'/"speed_limit_per_user": '$(echo ${ssspeed_limit_per_user})'/g' ${config_user_file}
}
#安装ShadowsocksR
installSSR(){
[[ -e $config_user_file ]] && echo -e "\033[41;37m [错误] \033[0m 发现已安装ShadowsocksR,如果需要继续安装,请先卸载 !" && exit 1
setUser
check_sys
# 系统判断
if [[ ${release} = "debian" ]]; then
debian_apt
elif [[ ${release} = "ubuntu" ]]; then
debian_apt
elif [[ ${release} = "centos" ]]; then
centos_yum
else
echo -e "\033[41;37m [错误] \033[0m 本脚本不支持当前系统 !" && exit 1
fi
#修改DNS为8.8.8.8
echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
JQ_install
cd /etc
#git config --global http.sslVerify false
env GIT_SSL_NO_VERIFY=true git clone -b manyuser https://github.com/shadowsocksr/shadowsocksr.git
[[ ! -e ${config_file} ]] && echo -e "\033[41;37m [错误] \033[0m ShadowsocksR 下载失败 !" && exit 1
cp ${config_file} ${config_user_file}
#修改配置文件的密码 端口 加密方式
cat > ${config_user_file}<<-EOF
{
"server": "0.0.0.0",
"server_ipv6": "::",
"server_port": ${ssport},
"local_address": "127.0.0.1",
"local_port": 1080,
"password": "${sspwd}",
"timeout": 120,
"udp_timeout": 60,
"method": "${ssmethod}",
"protocol": "${ssprotocol}",
"protocol_param": "${ssprotocol_param}",
"obfs": "${ssobfs}",
"obfs_param": "",
"speed_limit_per_con": ${ssspeed_limit_per_con},
"speed_limit_per_user": ${ssspeed_limit_per_user},
"dns_ipv6": false,
"connect_verbose_info": 0,
"redirect": "",
"fast_open": false
}
EOF
#添加新端口的规则
iptables_add
rc.local_ss_set
#启动SSR服务端,并判断是否启动成功
cd ${ssr_ss_file}
nohup python server.py a >> ssserver.log 2>&1 &
sleep 2s
PID=`ps -ef |grep -v grep | grep server.py |awk '{print $2}'`
if [[ ! -z "${PID}" ]]; then
viewUser
echo
echo -e "ShadowsocksR 安装完成 !"
echo -e "https://doub.io/ss-jc42/"
echo
echo "############################################################"
else
echo -e "\033[41;37m [错误] \033[0m ShadowsocksR服务端启动失败 !"
fi
}
installLibsodium(){
# 系统判断
check_sys
if [[ ${release} != "debian" ]]; then
if [[ ${release} != "ubuntu" ]]; then
if [[ ${release} != "centos" ]]; then
echo -e "\033[41;37m [错误] \033[0m 本脚本不支持当前系统 !" && exit 1
fi
fi
fi
if [[ ${release} != "centos" ]]; then
apt-get update && apt-get install -y gcc build-essential make
cd /root
wget --no-check-certificate -O libsodium.tar.gz https://github.com/jedisct1/libsodium/releases/download/${Libsodiumr_ver}/libsodium-${Libsodiumr_ver}.tar.gz
tar -xzf libsodium.tar.gz && mv libsodium-${Libsodiumr_ver} libsodium && cd libsodium
./configure --disable-maintainer-mode && make -j2 && make install
ldconfig
cd .. && rm -rf libsodium.tar.gz && rm -rf libsodium
else
yum update && yum install epel-release -y && yum install libsodium -y
fi
echo ${Separator_1} && echo
echo -e "Libsodium 安装完成 !"
echo -e "https://doub.io/ss-jc42/"
echo && echo ${Separator_1}
}
#修改单端口用户配置
modifyUser(){
SSR_install_status
now_mode=`jq '.port_password' ${config_user_file}`
[[ "${now_mode}" != "null" ]] && echo -e "\033[41;37m [错误] \033[0m 当前ShadowsocksR模式为 多端口,请检查 !" && exit 1
getUser
setUser
#修改配置文件的密码 端口 加密方式
set_config_port_pass
set_config_method_obfs_protocol
set_config_protocol_param
set_config_speed_limit_per
iptables_set
RestartSSR
}
#手动修改用户配置
manuallyModifyUser(){
SSR_install_status
port=`jq '.server_port' ${config_user_file}`
vi $config_user_file
ssport=`jq '.server_port' ${config_user_file}`
iptables_set
RestartSSR
}
#卸载ShadowsocksR
UninstallSSR(){
[[ ! -e $config_file ]] && echo -e "\033[41;37m [错误] \033[0m 没有发现安装ShadowsocksR,请检查 !" && exit 1
echo "确定要卸载ShadowsocksR ? (y/N)"
echo
read -p "(默认: n):" unyn
[[ -z ${unyn} ]] && unyn="n"
if [[ ${unyn} == [Yy] ]]; then
#停止ShadowsocksR服务端并删除防火墙规则,删除Shadowsocks文件夹。
PID=`ps -ef |grep -v grep | grep server.py |awk '{print $2}'`
[[ ! -z "${PID}" ]] && kill -9 ${PID}
cron_ssr=`crontab -l | grep "${ssr_file}/${auto_restart_cron}" | wc -l`
if [[ ${cron_ssr} > "0" ]]; then
crontab -l > ${ssr_file}"/crontab.bak"
sed -i "/\/etc\/shadowsocksr\/${auto_restart_cron}/d" ${ssr_file}"/crontab.bak"
crontab ${ssr_file}"/crontab.bak"
rm -rf ${ssr_file}"/crontab.bak"
fi
now_mode=`jq '.port_password' ${config_user_file}`
if [[ "${now_mode}" = "null" ]]; then
port=`jq '.server_port' ${config_user_file}`
iptables -D INPUT -m state --state NEW -m tcp -p tcp --dport ${port} -j ACCEPT
iptables -D INPUT -m state --state NEW -m udp -p udp --dport ${port} -j ACCEPT
else
user_total=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | wc -l`
for((integer = 1; integer <= ${user_total}; integer++))
do
port=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $1}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
iptables_del
done
fi
#取消开机启动
check_sys
rc.local_ss_del
rm -rf ${ssr_file} && rm -rf ${Libsodiumr_file} && rm -rf ${Libsodiumr_file}.tar.gz
echo && echo " ShadowsocksR 卸载完成 !" && echo
else
echo && echo "卸载已取消..." && echo
fi
}
# 更新ShadowsocksR
UpdateSSR(){
SSR_install_status
cd ${ssr_file}
git pull
RestartSSR
}
# 切换 单/多端口模式
Port_mode_switching(){
SSR_install_status
now_mode=`jq '.port_password' ${config_user_file}`
if [[ "${now_mode}" = "null" ]]; then
echo
echo -e " 当前ShadowsocksR模式:\033[42;37m 单端口 \033[0m"
echo
echo -e "确定要切换模式为 \033[42;37m 多端口 \033[0m ? (y/N)"
echo
read -p "(默认: n):" mode_yn
[[ -z ${mode_yn} ]] && mode_yn="n"
if [[ ${mode_yn} == [Yy] ]]; then
port=`jq '.server_port' ${config_user_file}`
setUser
iptables_set
cat > ${config_user_file}<<-EOF
{
"server": "0.0.0.0",
"server_ipv6": "::",
"local_address": "127.0.0.1",
"local_port": 1080,
"port_password":{
"${ssport}":"${sspwd}"
},
"timeout": 120,
"udp_timeout": 60,
"method": "${ssmethod}",
"protocol": "${ssprotocol}",
"protocol_param": "${ssprotocol_param}",
"obfs": "${ssobfs}",
"obfs_param": "",
"speed_limit_per_con": ${ssspeed_limit_per_con},
"speed_limit_per_user": ${ssspeed_limit_per_user},
"dns_ipv6": false,
"connect_verbose_info": 0,
"redirect": "",
"fast_open": false
}
EOF
RestartSSR
else
echo && echo " 已取消..." && echo
fi
else
echo
echo -e " 当前ShadowsocksR模式:\033[42;37m 多端口 \033[0m"
echo
echo -e "确定要切换模式为 \033[42;37m 单端口 \033[0m ? (y/N)"
echo
read -p "(默认: n):" mode_yn
[[ -z ${mode_yn} ]] && mode_yn="n"
if [[ ${mode_yn} == [Yy] ]]; then
user_total=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | wc -l`
for((integer = 1; integer <= ${user_total}; integer++))
do
port=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $1}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
iptables_del
done
setUser
iptables_add
cat > ${config_user_file}<<-EOF
{
"server": "0.0.0.0",
"server_ipv6": "::",
"server_port": ${ssport},
"local_address": "127.0.0.1",
"local_port": 1080,
"password": "${sspwd}",
"timeout": 120,
"udp_timeout": 60,
"method": "${ssmethod}",
"protocol": "${ssprotocol}",
"protocol_param": "${ssprotocol_param}",
"obfs": "${ssobfs}",
"obfs_param": "",
"speed_limit_per_con": ${ssspeed_limit_per_con},
"speed_limit_per_user": ${ssspeed_limit_per_user},
"dns_ipv6": false,
"connect_verbose_info": 0,
"redirect": "",
"fast_open": false
}
EOF
RestartSSR
else
echo && echo " 已取消..." && echo
fi
fi
}
List_multi_port_user(){
user_total=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | wc -l`
[[ ${socat_total} = "0" ]] && echo -e "\033[41;37m [错误] \033[0m 没有发现 多端口用户,请检查 !" && exit 1
user_list_all=""
user_id=0
check_sys
if [[ ${release} = "centos" ]]; then
for((integer = 1; integer <= ${user_total}; integer++))
do
user_port=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $1}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
user_password=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $2}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
user_id=$[$user_id+1]
user_list_all=${user_list_all}${user_id}". 用户端口: "${user_port}" 用户密码: "${user_password}"\n"
done
else
for((integer = ${user_total}; integer >= 1; integer--))
do
user_port=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $1}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
user_password=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $2}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
user_id=$[$user_id+1]
user_list_all=${user_list_all}${user_id}". 用户端口: "${user_port}" 用户密码: "${user_password}"\n"
done
fi
echo
echo -e "当前有 \033[42;37m "${user_total}" \033[0m 个用户配置。"
echo -e ${user_list_all}
}
# 添加 多端口用户配置
Add_multi_port_user(){
SSR_install_status
now_mode=`jq '.port_password' ${config_user_file}`
[[ "${now_mode}" = "null" ]] && echo -e "\033[41;37m [错误] \033[0m 当前ShadowsocksR模式为 单端口,请检查 !" && exit 1
set_port_pass
sed -i "7 i \" \"${ssport}\":\"${sspwd}\"," ${config_user_file}
sed -i "7s/^\"//" ${config_user_file}
iptables_add
RestartSSR
echo -e "\033[42;37m [信息] \033[0m ShadowsocksR 多端口用户 \033[42;37m [端口: ${ssport} , 密码: ${sspwd}] \033[0m 已添加!"
}
# 修改 多端口用户配置
Modify_multi_port_user(){
SSR_install_status
now_mode=`jq '.port_password' ${config_user_file}`
[[ "${now_mode}" = "null" ]] && echo -e "\033[41;37m [错误] \033[0m 当前ShadowsocksR模式为 单端口,请检查 !" && exit 1
echo "请输入数字 来选择你要修改的类型 :"
echo "1. 修改 用户端口/密码"
echo "2. 修改 全局协议/混淆"
read -p "(默认回车取消):" modify_type
[[ -z "${modify_type}" ]] && exit 1
if [[ ${modify_type} == "1" ]]; then
List_multi_port_user
while true
do
echo -e "请选择并输入 你要修改的用户前面的数字 :"
read -p "(默认回车取消):" del_user_num
[[ -z "${del_user_num}" ]] && exit 1
expr ${del_user_num} + 0 &>/dev/null
if [ $? -eq 0 ]; then
if [[ ${del_user_num} -ge 1 ]] && [[ ${del_user_num} -le ${user_total} ]]; then
set_port_pass
del_user_num_3=$[ $del_user_num + 6]
port=`sed -n "${del_user_num_3}p" ${config_user_file} | awk -F ":" '{print $1}' | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
password=`sed -n "${del_user_num_3}p" ${config_user_file} | awk -F ":" '{print $2}' | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
sed -i 's/"'$(echo ${port})'":"'$(echo ${password})'"/"'$(echo ${ssport})'":"'$(echo ${sspwd})'"/g' ${config_user_file}
iptables_set
RestartSSR
echo -e "\033[42;37m [信息] \033[0m ShadowsocksR 多端口用户 \033[42;37m ${del_user_num} \033[0m 已修改!"
break
else
echo "输入错误,请输入正确的数字 !"
fi
else
echo "输入错误,请输入正确的数字 !"
fi
done
elif [[ ${modify_type} == "2" ]]; then
set_others
getUser
set_config_method_obfs_protocol
set_config_protocol_param
set_config_speed_limit_per
RestartSSR
echo -e "\033[42;37m [信息] \033[0m ShadowsocksR 加密方式/协议/混淆等 已修改!"
fi
}
# 删除 多端口用户配置
Del_multi_port_user(){
SSR_install_status
now_mode=`jq '.port_password' ${config_user_file}`
[[ "${now_mode}" = "null" ]] && echo -e "\033[41;37m [错误] \033[0m 当前ShadowsocksR模式为 单端口,请检查 !" && exit 1
List_multi_port_user
user_total=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | wc -l`
[[ "${user_total}" -le "1" ]] && echo -e "\033[41;37m [错误] \033[0m 当前仅剩下一个多端口用户,无法删除 !" && exit 1
while true
do
echo -e "请选择并输入 你要删除的用户前面的数字 :"
read -p "(默认回车取消):" del_user_num
[[ -z "${del_user_num}" ]] && exit 1
expr ${del_user_num} + 0 &>/dev/null
if [[ $? -eq 0 ]]; then
if [[ ${del_user_num} -ge 1 ]] && [[ ${del_user_num} -le ${user_total} ]]; then
del_user_num_4=$[ $del_user_num + 6]
port=`sed -n "${del_user_num_4}p" ${config_user_file} | awk -F ":" '{print $1}' | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
iptables_del
del_user_num_1=$[ $del_user_num + 6 ]
sed -i "${del_user_num_1}d" ${config_user_file}
if [[ ${del_user_num} = ${user_total} ]]; then
del_user_num_1=$[ $del_user_num_1 - 1 ]
sed -i "${del_user_num_1}s/,$//g" ${config_user_file}
fi
RestartSSR
echo -e "\033[42;37m [信息] \033[0m ShadowsocksR 多端口用户 \033[42;37m ${del_user_num} \033[0m 已删除!"
break
else
echo "输入错误,请输入正确的数字 !"
fi
else
echo "输入错误,请输入正确的数字 !"
fi
done
}
# 显示用户连接信息
View_user_connection_info(){
SSR_install_status
check_sys
if [[ ${release} = "debian" ]]; then
debian_View_user_connection_info
elif [[ ${release} = "ubuntu" ]]; then
debian_View_user_connection_info
elif [[ ${release} = "centos" ]]; then
centos_View_user_connection_info
fi
}
debian_View_user_connection_info(){
now_mode=`jq '.port_password' ${config_user_file}`
if [[ "${now_mode}" = "null" ]]; then
now_mode="单端口模式" && user_total="1"
IP_total=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp6' |awk '{print $5}' |awk -F ":" '{print $1}' |sort -u |wc -l`
user_port=`jq '.server_port' ${config_user_file}`
user_IP=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp6' |grep "${user_port}" |awk '{print $5}' |awk -F ":" '{print $1}' |sort -u`
user_IP_total=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp6' |grep "${user_port}" |awk '{print $5}' |awk -F ":" '{print $1}' |sort -u |wc -l`
user_list_all="1. 用户端口: "${user_port}", 链接端口的IP总数: "${user_IP_total}", 链接端口的IP: "${user_IP}"\n"
echo -e "当前是 \033[42;37m "${now_mode}" \033[0m ,当前共有 \033[42;37m "${IP_total}" \033[0m 个IP正在链接。"
echo -e ${user_list_all}
else
now_mode="多端口模式" && user_total=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | wc -l`
IP_total=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp6' |awk '{print $5}' |awk -F ":" '{print $1}' |sort -u |wc -l`
user_list_all=""
user_id=0
for((integer = ${user_total}; integer >= 1; integer--))
do
user_port=`jq '.port_password' ${config_user_file} | sed '$d' | sed "1d" | awk -F ":" '{print $1}' | sed -n "${integer}p" | perl -e 'while($_=<>){ /\"(.*)\"/; print $1;}'`
user_IP=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp6' |grep "${user_port}" |awk '{print $5}' |awk -F ":" '{print $1}' |sort -u`
user_IP_total=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp6' |grep "${user_port}" |awk '{print $5}' |awk -F ":" '{print $1}' |sort -u |wc -l`
user_id=$[$user_id+1]
user_list_all=${user_list_all}${user_id}". 用户端口: "${user_port}" 链接端口的IP总数: "${user_IP_total}" 链接端口的IP: "${user_IP}"\n"
done
echo -e "当前是 \033[42;37m "${now_mode}" \033[0m ,当前有 \033[42;37m "${user_total}" \033[0m 个用户配置,当前共有 \033[42;37m "${IP_total}" \033[0m 个IP正在链接。"
echo -e ${user_list_all}
fi
}
centos_View_user_connection_info(){
now_mode=`jq '.port_password' ${config_user_file}`
if [[ "${now_mode}" = "null" ]]; then
now_mode="单端口模式" && user_total="1"
IP_total=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp' | grep '::ffff:' |awk '{print $4}' |sort -u |wc -l`
user_port=`jq '.server_port' ${config_user_file}`
user_IP=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp' |grep "${user_port}" | grep '::ffff:' |awk '{print $5}' |awk -F ":" '{print $4}' |sort -u`
user_IP_total=`netstat -anp |grep 'ESTABLISHED' |grep 'python' |grep 'tcp' |grep "${user_port}" | grep '::ffff:' |awk '{print $5}' |awk -F ":" '{print $4}' |sort -u |wc -l`
user_list_all="1. 用户端口: "${user_port}" 链接端口的IP总数: "${user_IP_total}" 链接端口的IP: "${user_IP}"\n"
echo -e "当前是 \033[42;37m "${now_mode}" \033[0m ,当前共有 \033[42;37m "${IP_total}" \033[0m 个IP正在链接。"
echo -e ${user_list_all}