forked from yonggekkk/Cloudflare_vless_trojan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kp.sh
143 lines (130 loc) · 5.06 KB
/
kp.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
#!/bin/bash
# 修改自Serv00|ct8老王保活脚本
# 转载请著名出自老王,请勿滥用
# 只保活节点,将此文件放到vps,填写以下服务器配置后bash kp.sh运行即可
SCRIPT_PATH="/root/kp.sh" # 脚本路径
# serv00或ct8服务器及端口配置。修改s0.serv00.com的服务区(默认s0),使用argo临时域名时,仅填 账号:密码:UUID:tcp1端口:tcp2端口:udp端口 即可
declare -A servers=( # 账号:密码:UUID:tcp1端口:tcp2端口:udp端口:argo固定域名:Argo固定隧道密钥(json或token)
["s0.serv00.com"]='ygkkk:A@123456:2f690ba2-b460-43ca-b9c3-1ac843bd2c70:5525:55255:55255'
# 添加更多服务器......
)
# 定义颜色
red() { echo -e "\e[1;91m$1\033[0m"; }
green() { echo -e "\e[1;32m$1\033[0m"; }
yellow() { echo -e "\e[1;33m$1\033[0m"; }
purple() { echo -e "\e[1;35m$1\033[0m"; }
export TERM=xterm
export DEBIAN_FRONTEND=noninteractive
install_packages() {
if [ -f /etc/debian_version ]; then
package_manager="apt-get install -y"
elif [ -f /etc/redhat-release ]; then
package_manager="yum install -y"
elif [ -f /etc/fedora-release ]; then
package_manager="dnf install -y"
elif [ -f /etc/alpine-release ]; then
package_manager="apk add"
else
red "不支持的系统架构!"
exit 1
fi
$package_manager sshpass curl netcat-openbsd jq cron >/dev/null 2>&1 &
}
install_packages
clear
# 添加定时任务
add_cron_job() {
if [ -f /etc/alpine-release ]; then
if ! command -v crond >/dev/null 2>&1; then
apk add --no-cache cronie bash >/dev/null 2>&1 &
rc-update add crond && rc-service crond start
fi
fi
# 检查定时任务是否已经存在
if ! crontab -l 2>/dev/null | grep -q "$SCRIPT_PATH"; then
(crontab -l 2>/dev/null; echo "*/2 * * * * /bin/bash $SCRIPT_PATH >> /root/keep_00.log 2>&1") | crontab -
green "已添加计划任务,每两分钟执行一次"
else
purple "计划任务已存在,跳过添加计划任务"
fi
}
add_cron_job
# 检查 TCP 端口是否通畅
check_tcp_port() {
local host=$1
local port=$2
nc -z -w 3 "$host" "$port" &> /dev/null
return $?
}
# 检查 Argo 隧道是否在线
check_argo_tunnel() {
local domain=$1
if [ -z "$domain" ]; then
return 1
else
http_code=$(curl -o /dev/null -s -w "%{http_code}\n" "https://$domain")
if [ "$http_code" -eq 404 ]; then
return 0
else
return 1
fi
fi
}
# 执行远程命令
run_remote_command() {
local host=$1
local ssh_user=$2
local ssh_pass=$3
local suuid=$4
local tcp1_port=$5
local tcp2_port=$6
local udp_port=$7
local argo_domain=${8}
local argo_auth=${9}
remote_command="UUID=$suuid vless_port=$tcp1_port vmess_port=$tcp2_port hy2_port=$udp_port ARGO_DOMAIN=$argo_domain ARGO_AUTH='$argo_auth' bash <(curl -Ls https://raw.githubusercontent.com/yonggekkk/Cloudflare_vless_trojan/main/serv00keep.sh)"
sshpass -p "$ssh_pass" ssh -o StrictHostKeyChecking=no "$ssh_user@$host" "$remote_command"
}
# 循环遍历服务器列表检测
for host in "${!servers[@]}"; do
IFS=':' read -r ssh_user ssh_pass suuid tcp1_port tcp2_port udp_port argo_domain argo_auth <<< "${servers[$host]}"
tcp_attempt=0
argo_attempt=0
max_attempts=3
time=$(TZ="Asia/Hong_Kong" date +"%Y-%m-%d %H:%M")
# 检查 TCP 端口
while [ $tcp_attempt -lt $max_attempts ]; do
if check_tcp_port "$host" "$tcp1_port"; then
green "$time TCP端口${tcp1_port}通畅 服务器: $host 账户: $ssh_user"
tcp_attempt=0
break
else
red "$time TCP端口${tcp1_port}不通 服务器: $host 账户: $ssh_user"
sleep 10
tcp_attempt=$((tcp_attempt+1))
fi
done
# 检查 Argo 隧道
while [ $argo_attempt -lt $max_attempts ]; do
if check_argo_tunnel "$argo_domain"; then
green "$time Argo 隧道在线 Argo域名: $argo_domain 账户: $ssh_user\n"
argo_attempt=0
break
else
red "$time Argo 隧道离线 Argo域名: $argo_domain 账户: $ssh_user"
sleep 10
argo_attempt=$((argo_attempt+1))
fi
done
# 如果3次检测失败,则执行 SSH 连接并执行远程命令
if [ $tcp_attempt -ge 3 ] || [ $argo_attempt -ge 3 ]; then
yellow "$time 多次检测失败,尝试通过SSH连接并远程执行命令 服务器: $host 账户: $ssh_user"
if sshpass -p "$ssh_pass" ssh -o StrictHostKeyChecking=no "$ssh_user@$host" -q exit; then
green "$time SSH远程连接成功 服务器: $host 账户 : $ssh_user"
output=$(run_remote_command "$host" "$ssh_user" "$ssh_pass" "$suuid" "$tcp1_port" "$tcp2_port" "$udp_port" "$argo_domain" "$argo_auth")
yellow "远程命令执行结果:\n"
echo "$output"
else
red "$time 连接失败,请检查你的账户密码 服务器: $host 账户: $ssh_user"
fi
fi
done