内网穿透实现公网访问域名走本地局域网以及实现代理请求
技术实现
使用免费的us.kg的二级域名,以及cloudflare大善人的网络穿透
前置
- 一个域名(可以白嫖us.kg的)
- 一个cloudflare账号(要使用网络通道)
- 域名要解析到cloudflare
域名注册
https://dash.domain.digitalplat.org/auth/login 通过这里可以注册3个免费的二级域名
域名修改Domain

cloudflare添加域名

free计划即可

继续激活

将生成的名字复制到域名那里

首页显示活动即设置成功

开发
测试代理是否有效的代码
import requests
from flask import *
# 以下测试代理———————————————————————————————————————————————————————————————————————————————————————————————————————————
local_host = "192.168.28.11" # 本机的局域网ip
# 7897是clash verge的局域网开放的端口,clash 应该是7890
proxies = {
"http": f"http://{local_host}:7897",
"https": f"http://{local_host}:7897",
}
# 请求
def get_requests(proxy):
temp = {}
uri = "https://httpbin.org/ip"
try:
not_proxy_response = requests.get(uri)
local_ip = not_proxy_response.json().get('origin','')
temp["not_proxy_response"] = local_ip
except Exception as e:
print(str(e))
temp["not_proxy_response"] = '请求失败'
try:
proxy_response = requests.get(uri, proxies=proxy)
print(proxy_response.text)
local_ip = proxy_response.json().get("origin", "")
temp["proxy_response"] = local_ip
except Exception as e:
print(str(e))
temp["proxy_response"] = "代理失败"
return temp
# 以上测试代理———————————————————————————————————————————————————————————————————————————————————————————————————————————
app = Flask(__name__)
@app.route("/")
def index():
try:
res = get_requests(proxies)
print(res)
return jsonify(res)
except Exception as e:
return jsonify({"message": str(e),"error":"error"})
if __name__ == '__main__':
app.run(host='0.0.0.0',port=5000,debug=True)
启动代码
python app.py
设置通道
- 添加隧道
cloudflare首页 -> Zero Trust(左侧导航栏) -> 网络(左侧导航栏) ->Tunnel(左侧导航栏)s -> 添加隧道




-
隧道类型
-
隧道类型选择cloudflared

-
给隧道命名
英文字符 eg:frp
- 安装并运行连接器
选择不同的平台安装不同的客户端
安装成功下边会更新链接器
然后点击下一步设置路由通道
- 路由隧道

开始访问
执行上面的代码

请求测试成功

原文:https://mp.weixin.qq.com/s/MFomIWZARpBqaOwuk_TN6g

4万+

被折叠的 条评论
为什么被折叠?



