代码拉取完成,页面将自动刷新
# -*- 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()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。