Serv00需要SSH登录保活 青龙脚本

在@xxrrrrr 大佬原本的基础,再加上坛友的基础上做了一个放在青龙上运行的脚本

# -- coding: utf-8 --
"""
cron: 0 15 */7 * *
new Env('Serv007 保活脚本');
"""
import os
import paramiko   #需要安装依赖 在pyhton 下
import sys
import time  

try:
    import notify
except ImportError:
    print("错误:无法导入 notify 模块,请确保 notify.py 存在且路径正确。")
    sys.exit(1)

def try_ssh_connection(server, username, password, label):
    """
    尝试通过 SSH 连接服务器
    """
    message = ""
    print(f"正在尝试连接到 {server},用户名:{username}(连接标签:{label})")
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    try:
        # 连接服务器
        client.connect(
            hostname=server,
            username=username,
            password=password,
            timeout=30,
        )
        # 执行命令
        stdin, stdout, stderr = client.exec_command("echo 'Hello from {label}'; date")
        output = stdout.read().decode().strip()
        print(output)
        message = f"✅ [SSH S7] {label} 连接成功!\n🔗 连接到: {server}\n👤 用户名: {username}\n🌐 面板地址: https://panel7.serv00.com/"
    except paramiko.ssh_exception.AuthenticationException:
        print(f"错误:{label} 身份验证失败!")
        message = f"❌ [SSH 保活通知] {label} 身份验证失败!"
    except paramiko.ssh_exception.SSHException as e:
        print(f"错误:{label} SSH 错误:{e}")
        message = f"❌ [SSH S7 保活通知] {label} SSH 错误!"
    except Exception as e:
        print(f"错误:{label} 连接失败:{e}")
        message = f"❌ [SSH S7 保活通知] {label} 连接失败!"
    finally:
        client.close()

    try:
        notify.send("SSH S7 保活通知", message)
    except Exception as e:
        print(f"错误:通知发送失败:{e}")
    print("通知已处理。")
    time.sleep(3)  

# 配置 SSH 连接信息
connections = [
    {"server": "s7.serv00.com", "username": "username1", "password": "password1", "label": "S7-连接1"},
    {"server": "s7.serv00.com", "username": "username2", "password": "password2", "label": "S7-连接2"},
]

# 尝试所有连接
for conn in connections:
    try_ssh_connection(conn["server"], conn["username"], conn["password"], conn["label"])

print("所有 SSH 连接尝试已完成。")
2 个赞

这东西不是登录后台就保活吗?

感谢大佬。

感谢大佬

咋方便咋来呗,多个选择而已。我是觉得青龙方便,我就放在青龙上运行

只要不封号 能活 咋地都行 我还有个前端特别好看 可惜不会弄

是的,整起来 大佬

是网页上登录也算保活了是吗?我注册了2个号,应该有2周了,就注册当天玩过,后面碰都没碰过,最近准备拿来玩玩。

佬友可不可以搞个青龙小白的教学,如何搭建青龙环境,薅薅羊毛之类的

此话题已在最后回复的 30 天后被自动关闭。不再允许新回复。