CloudFlare 是一个非常优秀的 CDN 服务,但是 CloudFlare 也有一个大的毛病大陆访问速度很慢。国外很多网站都在使用 Cloudflare CDN ,但分配给中国内地访客的 IP 并不友好(延迟高、丢包多、速度慢)。 虽然 Cloudflare 公开了所有 IP 段,但想要在这么多 IP 中找到适合自己的,怕是要累死,于是就有了这个脚本。
const res = await fetch("https://api.vvhan.com/tool/cf_ip"); const data = await res.json(); // 数据格式 // { // "success": true, // "data": { // "v4": { // "CM": [], // "CU": [], // "CT": [] // }, // "v6": { // "CM": [], // "CU": [], // "CT": [] // } // } // }
// 取最优选 IP IPv4 const CM_IP_V4 = data.v4.CM.reduce((minItem, currentItem) => { return currentItem.latency < minItem.latency ? currentItem : minItem; }, data.v4.CM[0]); const CU_IP_V4 = data.v4.CU.reduce((minItem, currentItem) => { return currentItem.latency < minItem.latency ? currentItem : minItem; }, data.v4.CU[0]); const CT_IP_V4 = data.v4.CT.reduce((minItem, currentItem) => { return currentItem.latency < minItem.latency ? currentItem : minItem; }, data.v4.CT[0]); const DNS_DATA_V4 = { 移动: CM_IP_V4.ip, 联通: CM_IP_V4.ip, 电信: CU_IP_V4.ip, 默认: CT_IP_V4.ip }; // 取最优选 IP IPv6 const CM_IP_V6 = data.v6.CM.reduce((minItem, currentItem) => { return currentItem.latency < minItem.latency ? currentItem : minItem; }, data.v6.CM[0]); const CU_IP_V6 = data.v6.CU.reduce((minItem, currentItem) => { return currentItem.latency < minItem.latency ? currentItem : minItem; }, data.v6.CU[0]); const CT_IP_V6 = data.v6.CT.reduce((minItem, currentItem) => { return currentItem.latency < minItem.latency ? currentItem : minItem; }, data.v6.CT[0]); const DNS_DATA_V6 = { 移动: CM_IP_V6.ip, 联通: CM_IP_V6.ip, 电信: CU_IP_V6.ip, 默认: CT_IP_V6.ip };
DnsPodDomainList.forEach(async i => { try { const res = await client.ModifyRecord({ Domain, RecordType: i.Type, RecordLine: "", RecordLineId: i.LineId, Value: i.Type == "A" ? DNS_DATA_V4[i.Line] : DNS_DATA_V6[i.Line], RecordId: i.RecordId, SubDomain }); console.log(res); } catch (error) { console.log(error); } });
1 kwkwkkk 2024-08-27 16:56:19 +08:00 试了下挺好用的,已 star |
2 chenxuuu 2024-08-27 17:00:18 +08:00 比较好奇,cf 不是要配置 ns 服务器的吗,这个难道是 cname 方式接入的,所以可以直接用 ip 指向 cf ? |
![]() | 3 JensenQian 2024-08-27 17:07:24 +08:00 ![]() @chenxuuu #2 可以 saas 实现 cname 接入的 |
![]() | 4 icaolei 2024-08-27 17:09:00 +08:00 |
![]() | 5 Solix 2024-08-27 17:14:20 +08:00 做优选的项目太多了,主要是慢慢都不维护了 |
![]() | 6 uxiaohan OP ![]() @chenxuuu Cloudflare Pages 可以 cname 解析,Cloudflare 域名停放后,可以 Saas 回源进行 Ip 优选 |
![]() | 7 zhiyu1998 2024-08-27 19:51:07 +08:00 via iPhone 我说怎么看着地址熟悉 有幸用过 han 哥的公益 API |
![]() | 9 MoonWalker 2024-08-28 10:10:43 +08:00 感谢....api 稳定吗,能否私有化部署这个 api? |
![]() | 10 dufu1991 2024-08-28 10:12:52 +08:00 我是新手,不知道怎么用。我的静态资源再 GitHub pages 上,是不是无法使用这个项目优选? |