const server = '
https://223.6.6.6/dns-query'; // DoH
const edns = ['
140.207.122.197', '
183.47.126.35']; // 不同运营商/地区的 IP, 作为 EDNS Client Subnet (ECS)
const type = 'A'; // A 或 AAAA
if (!ProxyUtils.isIP($server.server)) {
const cache = scriptResourceCache;
const resolve = async (url, domain, type, edns) => {
const id = `${url}:${domain}:${type}:${edns}`;
const cached = cache.get(id);
// 使用缓存
if (cached) return cached;
const res = await ProxyUtils.doh({
url,
domain,
type,
edns,
});
const { answers } = res;
if (!Array.isArray(answers) || answers.length === 0) {
throw new Error('No answers');
}
const result = answers
.filter((i) => i?.type === type)
.map((i) => i?.data)
.filter((i) => i);
if (result.length === 0) {
throw new Error('No answers');
}
cache.set(id, result);
return result;
};
const result = await Promise.all(
edns.map((i) => resolve(server, $server.server, type, i)),
);
$server._resolved_ips = [...new Set(result.flat())];
}