1 Star 0 Fork 0

xiaoduan/myQLScript

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
内网穿透localtunnel(1).py 3.18 KB
一键复制 编辑 原始数据 按行查看 历史
duanmk 提交于 2024-03-27 10:17 +08:00 . first commit
# -*- coding: UTF-8 -*-
# Version: v1.0
# Created by lstcml on 2022/08/08
# 建议定时60分钟:*/60 * * * *
import os
import sys
import requests
from time import sleep
def update():
print("当前运行的脚本版本:" + str(version))
try:
r1 = requests.get("https://gitee.com/lstcml/qinglongscripts/raw/master/nwct/nwct_localtunnel.py").text
r2 = re.findall(re.compile("version = \d.\d"), r1)[0].split("=")[1].strip()
if float(r2) > version:
print("发现新版本:" + r2)
print("正在自动更新脚本...")
os.system("kill -9 `ps -ef | grep 'ngrok.py' | grep -v 'grep' | awk '{print $1}'`")
os.system("rm -f ngrok.py")
os.system("ql raw https://gitee.com/lstcml/qinglongscripts/raw/master/nwct/nwct_localtunnel.py &")
except:
pass
# 进程守护
def process_daemon():
global qlurl
qlurl = get_url()
try:
res = requests.get(qlurl + "/login").text
if "/images/g5.ico" in res:
return True
else:
return False
except:
return False
# 获取穿透url
def get_url():
try:
with open('localtunnel.lstcml', encoding='utf-8') as f:
_content = f.read()
if 'your url is' in _content:
print("获取穿透链接成功...")
return _content.split(': ')[1].replace('\n','')
else:
return 'https://gitee.com/lstcml/qinglongscripts'
except:
return 'https://gitee.com/lstcml/qinglongscripts'
# 执行程序
def start_nwct():
if not process_daemon():
os.system('lt --port 5700 > localtunnel.lstcml &')
print("正在启动内网穿透...")
sleep(10)
print("正在检测穿透状态...")
if process_daemon():
if load_send():
print("启动内网穿透成功!\n青龙面板:%s" % qlurl)
print("若访问穿透地址出现安全检测界面,点击蓝色'Click to Continue'按钮可跳过!")
send("内网穿透通知", "青龙面板访问地址:" + qlurl)
else:
print("启动内网穿透失败...")
else:
print("穿透程序已在运行...\n青龙面板:%s" % qlurl)
# 推送
def load_send():
global send
cur_path = os.path.abspath(os.path.dirname(__file__))
sys.path.append(cur_path)
sendNotifPath = cur_path + "/sendNotify.py"
if not os.path.exists(sendNotifPath):
res = requests.get("https://gitee.com/lstcml/qinglongscripts/raw/master/sendNotify.py")
with open(sendNotifPath, "wb") as f:
f.write(res.content)
try:
from sendNotify import send
return True
except:
print("加载通知服务失败!")
return False
if __name__ == '__main__':
version = 1.0
try:
check_update = os.environ['qlnwctupdate']
except:
check_update = "true"
if check_update != "false":
update()
else:
print("变量qlnwctupdate未设置,脚本自动更新未开启!")
if os.system('lt --help >/dev/null 2>&1') !=0:
os.system('npm install -g localtunnel >/dev/null 2>&1')
start_nwct()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/duan-mingkun/my-qlscript.git
[email protected]:duan-mingkun/my-qlscript.git
duan-mingkun
my-qlscript
myQLScript
master

搜索帮助