利用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/
没有回复内容