Skip to content

Commit 5dd7951

Browse files
authored
Update 一键所有VPS安装流量出售工具.py
优化代码 运行更稳定
1 parent 6fa15d5 commit 5dd7951

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

一键所有VPS安装流量出售工具.py

+37-9
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,53 @@
1010
# 添加更多服务器
1111
]
1212

13+
1314
# 定义更新操作
1415
def update_server(name, hostname, port, username, password):
1516
try:
1617

1718

18-
print(f"在服务器 {name} 上安装流量出售工具")
1919
client = paramiko.SSHClient()
2020
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
2121
client.connect(hostname, port=port, username=username, password=password)
2222

2323

24+
# 执行步骤1: 更新操作
25+
print(f" {name} 更新")
26+
stdin, stdout, stderr = client.exec_command("apt update -y && apt install -y curl wget sudo socat htop")
27+
28+
print(f"正在更新:")
29+
while not stdout.channel.exit_status_ready():
30+
if stdout.channel.recv_ready():
31+
print(stdout.channel.recv(1024).decode(), end="")
32+
33+
# 检查执行状态
34+
if stderr.channel.recv_exit_status() == 0:
35+
print(f"更新成功")
36+
else:
37+
print(f"更新失败")
38+
39+
print()
40+
41+
42+
print(f"{name} 安装 Docker")
43+
stdin, stdout, stderr = client.exec_command("wget -qO- https://get.docker.com/ | sh")
44+
45+
print(f"正在安装 Docker:")
46+
while not stdout.channel.exit_status_ready():
47+
if stdout.channel.recv_ready():
48+
print(stdout.channel.recv(1024).decode(), end="")
49+
50+
# 检查执行状态
51+
if stderr.channel.recv_exit_status() == 0:
52+
print(f"安装 Docker 成功")
53+
else:
54+
print(f"安装 Docker 失败")
55+
56+
print()
57+
58+
59+
print(f"在服务器 {name} 上安装流量出售工具")
2460
stdin, stdout, stderr = client.exec_command("docker run -d --name tmd --restart=always traffmonetizer/cli start accept --token VM+OdtNp5mupfl8I2w0EZswkOJ8WSuTuMe/kDV02gS8=")
2561

2662
while not stdout.channel.exit_status_ready():
@@ -33,14 +69,6 @@ def update_server(name, hostname, port, username, password):
3369
else:
3470
print(f"安装失败")
3571

36-
# 关闭 SSH 连接
37-
client.close()
38-
39-
40-
# 执行步骤2: 安装 Docker
41-
client = paramiko.SSHClient()
42-
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
43-
client.connect(hostname, port=port, username=username, password=password)
4472

4573
stdin, stdout, stderr = client.exec_command("docker ps -a")
4674

0 commit comments

Comments
 (0)