【更新】手机青龙面板内网穿透

内网穿透脚本更新了,适用于手机青龙面板。运行效果如下图,访问图片中那个地址就可以随时随地控制家里破手机里的青龙了。

9ba403348cd70a1d0ced833707a33ca9.png


1. 新建个环境变量:“qlsubdomain”,值为字母+数字组合,自己随意取。

285fd785115b3588d4c4afebcd34a408.png

2. 拉库命令(最好先删除之前的脚本):

ql raw https://gitee.com/lstcml/qinglongscripts/raw/master/nwct/nwct_localtunnel.py

不喜欢拉库的直接复制下面的代码自己创建即可:

# -*- coding: UTF-8 -*-
# Version: v1.4
# Created by lstcml on 2022/08/08
# 建议定时60分钟:*/60 * * * *


'''
更新记录:
v1.4
1、修复一些bug;


v1.3
1、修复一些bug;


v1.2
1、因需点击才能跳转,去除穿透校验;
2、强制设置前缀域名;
3、去除微信推送;


v1.1
1、自动安装必要模块;
2、支持自定义域名前缀;
'''
import os
import re
import sys
import requests
from time import sleep


def update():
    print("当前运行的脚本版本:" + str(version))
    sys.stdout.flush()
    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("正在自动更新脚本...")
            sys.stdout.flush()
            os.system("ql raw https://gitee.com/lstcml/qinglongscripts/raw/master/nwct/nwct_localtunnel.py &")
            os._exit()
    except:
        pass


# 判断是否包含中文
def other_character(str):
    match = re.compile(u'[\u4e00-\u9fa5]').search(str)
    if match:
        return False
    else:
        if str.isalnum():
            return True
        else:
            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("获取穿透链接成功...")
                sys.stdout.flush()
                return _content.split(': ')[1].replace('\n','')
            else:
                return 'failed'
    except:
        return 'failed'


# 执行程序
def start_nwct():
    os.system('kill -9 `ps -ef | grep "lt --port" | grep -v grep | awk \'{print $1}\'`')
    os.system('lt --port 5700 -s ' + subdomain + ' > localtunnel.lstcml &')
    print("正在启动内网穿透...")
    sleep(10)
    print("正在获取穿透链接...")
    qlurl = get_url()
    if 'failed' not in qlurl:
        print("启动内网穿透成功!\n青龙面板:%s" % qlurl)
        print("若访问穿透地址出现安全检测界面,点击蓝色'Click to Continue'按钮可跳过!")
        sys.stdout.flush()
    else:
        print('获取穿透链接失败,请重试!')
    # send("内网穿透通知", "青龙面板访问地址:" + 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.4
    try:
        subdomain = os.environ['qlsubdomain']
    except:
        subdomain = ""
    try:
        check_update = os.environ['qlnwctupdate']
    except:
        check_update = "true"
    try:
        import requests
    except:
        os.system('pip3 install requests >/dev/null 2>&1')
 
    if check_update != "false":
        update()
    else:
        print("变量qlnwctupdate未设置,脚本自动更新未开启!")
        sys.stdout.flush()
    if os.system('lt --help >/dev/null 2>&1') !=0:
        os.system('npm install -g localtunnel >/dev/null 2>&1')
    if len(subdomain) < 1:
        print("变量qlsubdomain未设置!")
        sys.stdout.flush()
    else:
        if other_character(subdomain):
            start_nwct()
        else:
            print("变量qlsubdomain仅支持英文数字组合!")

3. 运行脚本,查看运行日记,复制出访问地址!!!本次脚本去除了通知,所以要自己查看下日记。

注:免费的东西,不要纠结网速了,还是比较稳定的,地址目前测试一周没变化。


就这样吧,玩起来吧~欢迎打赏,感谢支持~d9e1a53e32f6f8270ed93293364bbc77.png

  • 4
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值