折腾啥 头像

消息来源频道

折腾啥

@zhetengsha

频道40,410 位成员公开可见0 人在线

Power Users/Automators 折腾/讨论/分享各种开源工具/脚本/自动化工作流 👥 群组 @zhetengsha_group 📌 资源合集导航 https://t.me/zhetengsha/2 🎁 恰饭推荐 https://t.me/zhetengsha/957 📢 广告投放 @xream Buy ads: https://telega.io/c/zhetengsha feedId:55438372655431680+userId:62307599601855488

成员规模40,410 位成员
在线情况0 人在线
消息总数4,340 条消息
浏览量总数7,753,402 次浏览

在这个频道里搜索消息……

t.me/zhetengsha

Sub-Store 小课堂: 域名解析多 IP 裂变节点
群友的需求
使用了域名解析功能,如果有一个域名解析出来多个ip,如何让每个ip都变成一个节点
1. 如果你的真实需求是解析出不同运营商/不同地区的不同 IP
1.1 请把 Sub-Store 内置的域名解析这一步操作换成脚本操作, 内容为:
const server = 'https://223.6.6.6/dns-query'; // DoH 阿里和腾讯的可能会触发限速 可以换别的试试
const edns = [{ name: '联通', ip: '119.36.124.169' }, { name: '电信', ip: '116.207.181.162' }, { name: '移动', ip: '111.47.229.151' }]; // 不同运营商/地区的 IP, 作为 EDNS Client Subnet (ECS)
const type = 'A'; // A 或 AAAA
if (!ProxyUtils.isIP($server.server)) {
const cache = scriptResourceCache;
const resolve = async (url, domain, type, { name, ip }) => {
const id = ${url}:${domain}:${type}:${name}:${ip};
const cached = cache.get(id);
// 使用缓存
if (cached) return cached;
const res = await ProxyUtils.doh({
url,
domain,
type,
edns: ip,
});
const { answers } = res;
if (!Array.isArray(answers) || answers.length === 0) {
throw new Error('No answers');
}
let result = answers
.filter((i) => i?.type === type)
.map((i) => i?.data)
.filter((i) => i);
if (result.length === 0) {
throw new Error('No answers');
}
result = [...new Set(result.flat())];
const data = {
ip,
name,
result,
}
cache.set(id, data);
return data;
};
$server._domain = $server.server
$server._resolved_ips = await Promise.all(
edns.map(({ip, name}) => resolve(server, $server.server, type, { ip, name })),
);
}
1.2 然后接一个脚本操作
function operator(proxies = []) {
const list = []
proxies.map((p = {}) => {
let ips = p._resolved_ips
if (Array.isArray(ips) && ips.length > 0) {
ips.map(({ name, ip, result }) => {
result.map((server, index) => {
list.push({
...p,
name: ${name} ${index + 1} - ${p.name},
server,
})
})
})
// 取消下面几行的注释, 可以添加一个原始域名的节点
// list.push({
// ...p,
// name: 原始 - ${p.name},
// server: p._domain,
// })
} else {
list.push(p)
}
})
return list
}
2. 如果你的需求只是裂变, 先添加一个内置的域名解析, 然后添加一个脚本操作:
function operator(proxies = []) {
const list = []
proxies.map((p = {}) => {
let ips = p._resolved_ips
if (Array.isArray(ips) && ips.length > 0) {
ips.map((server, index) => {
list.push({
...p,
name: ${p.name}${index + 1},
server,
})
})
// 取消下面几行的注释, 可以添加一个原始域名的节点
// list.push({
// ...p,
// name: 原始 - ${p.name},
// server: p._domain,
// })
} else {
list.push(p)
}
})
return list
}
🤭 Sub-Store 合集 🧐 频道资源合集 😄 恰饭推荐 💬 群组
🥰 #SubStore #Sub-Store #小课堂 #tips #域名解析 #裂变 #IP #节点