-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy path一键所有VPS更新系统.py
53 lines (40 loc) · 1.85 KB
/
一键所有VPS更新系统.py
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
import paramiko
# 定义服务器列表,包括服务器名称、IP地址、端口号、用户名和密码
servers = [
{"name": "美国", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456"},
{"name": "不丹", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456"},
{"name": "毛里求斯", "hostname": "1.1.1.1", "port": 22, "username": "root", "password": "123456"},
# 添加更多服务器
]
# 定义更新操作
def update_server(name, hostname, port, username, password):
try:
# 连接服务器
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname, port=port, username=username, password=password)
stdin, stdout, stderr = client.exec_command("DEBIAN_FRONTEND=noninteractive apt update && DEBIAN_FRONTEND=noninteractive apt full-upgrade -y")
print(f" {name} 开始更新")
while not stdout.channel.exit_status_ready():
if stdout.channel.recv_ready():
print(stdout.channel.recv(1024).decode(), end="")
# 检查更新状态
if stderr.channel.recv_exit_status() == 0:
print(f"更新成功")
else:
print(f"更新失败")
# 关闭 SSH 连接
client.close()
print()
except Exception as e:
print(f"连接 {name} 失败 \n")
# 遍历服务器列表,逐一更新
for server in servers:
name = server["name"]
hostname = server["hostname"]
port = server["port"]
username = server["username"]
password = server["password"]
update_server(name, hostname, port, username, password)
# 等待用户按下任意键后关闭窗口
input("按任意键关闭窗口...")