共计 541 个字符,预计需要花费 2 分钟才能阅读完成。
利用 cloudflare workers 搭建查询用户 ip 代码
因为 cloudflare 是给出两个解析记录,一个是 ipv4,一个是 ipv6
这样其实也有个优点,这样就可以分出三个解析记录
分别是检查网络优先级,检查 ipv6 地址,检查 ipv4 地址
代码用的都是一个,仅仅是在 DNS 解析记录那里,不要使用 cloudflare 的代理,给查询 ipv4 的域名指向 workers 的 ipv4,给查询 ipv6 的域名指向 workers 的 ipv6,如果想查询优先级的,直接 workers 默认就可以了。
以下为 workers 的代码
export default {
async fetch(request) {
//get.geeip.com
return new Response(request.headers.get(‘CF-Connecting-IP’), {
status: 200,
headers: {“Content-Type”: “text/html;charset=UTF-8”},
})
}
}; 复制代码
演示网址:
IP 优先级检测,https://get.geeip.com/
ipv4 地址检测,https://ipv4.geeip.com/
ipv6 地址检测,https://ipv6.geeip.com/
正文完