支持一级泛域名解析,例如主域名exampe.com,那么只支持*.example.com,三级泛域名由于ssl证书免费版没有,需要升级付费版本,
dns解析的时候将泛域名添加一个cname记录,指向自己的隧道id.cfargotunnel.com即可
<tunnel id>.cfargotunnel.com,
获取当前的访问域名和客户端真实ip代码为
from flask import Flask, request, render_template_string
app = Flask(__name__)
@app.route('/')
def show_domain():
# Cloudflare 通过 CF-Connecting-IP 传递真实客户端 IP
client_ip = request.headers.get('CF-Connecting-IP')
# 如果头不存在(比如直接访问,非 Cloudflare),回退到 remote_addr
if not client_ip:
client_ip = request.remote_addr
# 获取用户访问时用的完整 Host(含端口)
full_host = request.host
# 只取域名/IP(不含端口)
domain_only = request.host.split(':')[0]
html = f'''
<h2>你当前访问的地址:</h2>
<p>客户端真实ip: <strong>{client_ip}</strong></p>
<p>完整 Host(含端口): <strong>{full_host}</strong></p>
<p>仅域名/IP: <strong>{domain_only}</strong></p>
'''
return render_template_string(html)
if __name__ == '__main__':
# 绑定到所有接口,方便从外部访问(适合 CentOS 环境)
app.run(host='0.0.0.0', port=8000, debug=True) 网友回复


