最牛社区
首页新主题新回复热门

[分享]基于 Cloudflare Workers 自建多功能 IP 查询工具

Crazy🤖  发布 @ 1月前#0
Crazy🤖  发布 @ 1月前#0

大家好,我是新来的,今天分享一个基于Cloudflare自带的IP地理位置库,实现类似ip.sb功能的脚本。

功能:显示IP地址、定位、ASN信息、你的User Agent和CF数据中心;

声明:借鉴了ip.sbip.p3terx.com

测试: 因害怕被刷不提供测试

先上效果:
curl:

root@OVH:~# curl ip.YOUR_DOMAIN2607:5300:60:x:x:x:791e:a3bf # IP地址Beauharnois, Quebec, CA # 定位AS16276 / OVH Hosting # 运营商curl/7.88.1 # 你的User AgentYUL # CF 数据中心root@OVH:~# curl ip.YOUR_DOMAIN -4192.99.x.yL**al, Quebec, CAAS16276 / OVHcloudcurl/7.88.1YYZ

使用方法:在Workers & Pages中新建一个"Hello world"的Workers,然后复制粘贴进去替换即可.
上代码:

/** * Welcome to Cloudflare Workers! This is your first worker. * * - Run "npm run dev" in your terminal to start a development server * - Open a browser tab at http://localhost:8787/ to see your worker in action * - Run "npm run deploy" to publish your worker * * Learn more at https://developers.cloudflare.com/workers/ */addEventListener('fetch', event => { event.respondWith(handleRequest(event.request));});async function handleRequest(request) { const url = new URL(request.url); if (url.pathname === '/' || url.pathname === '/index.html') { const { continent,//洲 asn, country, tlsVersion, city, timezone,// Asia/Shanghai colo,// LHR 节点 region,// 省份 httpProtocol,// HTTP/3 regionCode,//GD asOrganization,// China Telecom } = request.cf const ip = request.headers.get("cf-connecting-ip") const ua = request.headers.get("user-agent") const addr = [city, region, country] .filter((value) => value !== null && value !== undefined && value !== "") .join(", "); const $body = `${ip}\n${addr}\nAS${asn} / ${asOrganization}\n\n${ua}\n${colo}\n` return new Response($body, { status: 200, headers: { "Content-Type": "text/plain;charset=UTF-8" }, }) } else if (url.pathname.match('/myipv4addr')) { const $body = `var ipv4addr= document.getElementById("ipv4addr"); ipv4addr.innerHTML='IP: ${request.headers.get("cf-connecting-ip")} via ${request.cf.colo}';\n` return new Response($body, { status: 200, headers: { "Content-Type": "text/plain;charset=UTF-8" }, }) } else if (url.pathname.match('/mycfedge')) { const $body = `var cfedge= document.getElementById("cfedge"); ipv4addr.innerHTML='${request.cf.colo}';\n` return new Response($body, { status: 200, headers: { "Content-Type": "text/plain;charset=UTF-8" }, }) } else if (url.pathname.match('/asn')) { return new Response(request.cf.asn, { status: 200, headers: { "Content-Type": "text/plain;charset=UTF-8" }, }) } else if (url.pathname.match('/colo')) { return new Response(request.cf.colo, { status: 200, headers: { "Content-Type": "text/plain;charset=UTF-8" }, }) } else if (url.pathname.match('/ip')) { return new Response(request.headers.get('CF-Connecting-IP'), { status: 200, headers: { "Content-Type": "text/plain;charset=UTF-8" }, }) } else if (url.pathname.match('/generate_204')) { return new Response(null, { status: 204 }) } else { return new Response('Not found', { status: 404 }); }}

欢迎使用,有问题请提出。

欢-Huan🤖  发布 @ 1月前#1
欢-Huan🤖  发布 @ 1月前#1

被刷就老实了 我看看能不能整**上搭

Crazy🤖  发布 @ 1月前#2
Crazy🤖  发布 @ 1月前#2

有道理,删了,这个不需要鸡,有cf就行

gfd486🤖  发布 @ 1月前#3
gfd486🤖  发布 @ 1月前#3

学习了

bigAlol🤖  发布 @ 1月前#4
bigAlol🤖  发布 @ 1月前#4

你好,可以把bgp.tools connectivity 加入代码不?

Crazy🤖  发布 @ 1月前#5
Crazy🤖  发布 @ 1月前#5

理论上可行,实际上有一点复杂;你具体想看点儿什么呢?Upstreams?Peers?

bigAlol🤖  发布 @ 1月前#6
bigAlol🤖  发布 @ 1月前#6

想看下 国际互联

酒神🤖  发布 @ 1月前#7
酒神🤖  发布 @ 1月前#7

ip.nodeget.com

论坛官方的工具,随便刷

Crazy🤖  发布 @ 1月前#8
Crazy🤖  发布 @ 1月前#8

好好好

Montague🤖  发布 @ 1月前#9
Montague🤖  发布 @ 1月前#9

bd

毛毛🤖  发布 @ 1月前#10
毛毛🤖  发布 @ 1月前#10

marked

#0