feat: 随机IP范围改为在线获取

This commit is contained in:
cmliu
2025-08-08 03:25:57 +08:00
parent 0f2fa1fefd
commit 8a428457dc
2 changed files with 17 additions and 28 deletions

View File

@@ -411,7 +411,7 @@ async function handleTCPOutBound(remoteSocket, addressType, addressRemote, portR
if (!useSocks) {
const nat64Proxyip = `[${await resolveToIPv6(addressRemote)}]`;
log(`NAT64 代理连接到 ${nat64Proxyip}:443`);
tcpSocket = await connectAndWrite(nat64Proxyip, '443');
tcpSocket = await connectAndWrite(nat64Proxyip, 443);
}
tcpSocket.closed.catch(error => {
console.log('retry tcpSocket closed error', error);
@@ -1492,28 +1492,17 @@ async function 生成配置信息(userID, hostName, sub, UA, RproxyIP, _url, fak
if ((addresses.length + addressesapi.length + addressesnotls.length + addressesnotlsapi.length + addressescsv.length) == 0) {
// 定义 Cloudflare IP 范围的 CIDR 列表
let cfips = [
'103.21.244.0/24',
'104.16.0.0/13',
'104.24.0.0/14',
'172.64.0.0/14',
'104.16.0.0/14',
'104.24.0.0/15',
'141.101.64.0/19',
'172.64.0.0/14',
'188.114.96.0/21',
'190.93.240.0/21',
'162.159.152.0/23',
'104.16.0.0/13',
'104.24.0.0/14',
'172.64.0.0/14',
'104.16.0.0/14',
'104.24.0.0/15',
'141.101.64.0/19',
'172.64.0.0/14',
'188.114.96.0/21',
'190.93.240.0/21',
];
let cfips = ['104.16.0.0/13'];
// 请求 Cloudflare CIDR 列表
try {
const response = await fetch('https://raw.githubusercontent.com/cmliu/cmliu/main/CF-CIDR.txt');
if (response.ok) {
const data = await response.text();
cfips = await 整理(data);
}
} catch (error) {
console.log('获取 CF-CIDR 失败,使用默认值:', error);
}
// 生成符合给定 CIDR 范围的随机 IP 地址
function generateRandomIPFromCIDR(cidr) {
@@ -2471,8 +2460,8 @@ async function KV(request, env, txt = 'ADD.txt') {
}
async function resolveToIPv6(target) {
const defaultAddress = atob('cHJveHlpcC5jbWxpdXNzc3MubmV0');
if (!DNS64Server) {
const defaultAddress = atob('cHJveHlpcC5jbWxpdXNzc3MubmV0');
try {
const response = await fetch(atob('aHR0cHM6Ly8xLjEuMS4xL2Rucy1xdWVyeT9uYW1lPW5hdDY0LmNtbGl1c3Nzcy5uZXQmdHlwZT1UWFQ='), {
headers: { 'Accept': 'application/dns-json' }
@@ -2683,10 +2672,10 @@ async function resolveToIPv6(target) {
if (isIPv6(target)) return target; // IPv6直接返回
const ipv4 = isIPv4(target) ? target : await fetchIPv4(target);
const nat64 = DNS64Server.endsWith('/96') ? convertToNAT64IPv6(ipv4) : await queryNAT64(ipv4 + atob('LmlwLjA5MDIyNy54eXo='));
return isIPv6(nat64) ? nat64 : atob('cHJveHlpcC5jbWxpdXNzc3MubmV0');
return isIPv6(nat64) ? nat64 : defaultAddress;
} catch (error) {
console.error('解析错误:', error);
return atob('cHJveHlpcC5jbWxpdXNzc3MubmV0');
return defaultAddress;
}
}

View File

@@ -1,4 +1,4 @@
name = "v20250723"
name = "v20250807"
main = "_worker.js"
compatibility_date = "2025-07-23"
compatibility_date = "2025-08-07"
keep_vars = true