|
| 1 | +import DNSOverHTTPS from "../src/lib/dns/https.js"; |
| 2 | + |
| 3 | +// 境外DNS的DoH配置sni测试 |
| 4 | +const servers = [ |
| 5 | + 'https://dns.quad9.net/dns-query', |
| 6 | + 'https://max.rethinkdns.com/dns-query', |
| 7 | + 'https://sky.rethinkdns.com/dns-query', |
| 8 | + 'https://doh.opendns.com/dns-query', |
| 9 | + 'https://1.1.1.1/dns-query', |
| 10 | + 'https://dns.cloudflare.com/dns-query', |
| 11 | + 'https://cloudflare-dns.com/dns-query', |
| 12 | + 'https://dns.google/dns-query', |
| 13 | + 'https://dns.bebasid.com/unfiltered', |
| 14 | + 'https://0ms.dev/dns-query', |
| 15 | + 'https://dns.decloudus.com/dns-query', |
| 16 | + 'https://wikimedia-dns.org/dns-query', |
| 17 | + 'https://doh.applied-privacy.net/query', |
| 18 | + 'https://private.canadianshield.cira.ca/dns-query', |
| 19 | + // 'https://dns.controld.com/comss', // 可直连,无需SNI |
| 20 | + 'https://kaitain.restena.lu/dns-query', |
| 21 | + 'https://doh.libredns.gr/dns-query', |
| 22 | + 'https://doh.libredns.gr/ads', |
| 23 | + 'https://dns.switch.ch/dns-query', |
| 24 | + 'https://doh.nl.ahadns.net/dns-query', |
| 25 | + 'https://doh.la.ahadns.net/dns-query', |
| 26 | + 'https://dns.dnswarden.com/uncensored', |
| 27 | + 'https://doh.ffmuc.net/dns-query', |
| 28 | + 'https://dns.oszx.co/dns-query', |
| 29 | + 'https://doh.tiarap.org/dns-query', |
| 30 | + 'https://jp.tiarap.org/dns-query', |
| 31 | + 'https://dns.adguard.com/dns-query', |
| 32 | + 'https://rubyfish.cn/dns-query', |
| 33 | + 'https://i.233py.com/dns-query' |
| 34 | + |
| 35 | +] |
| 36 | + |
| 37 | +const hostname1 = 'github.com' |
| 38 | +const sni = 'baidu.com' |
| 39 | + |
| 40 | +console.log(`\n--------------- 测试DoH的SNI功能:共 ${servers.length} 个DoH服务 ---------------\n`) |
| 41 | + |
| 42 | +let n = 0 |
| 43 | +let success = 0 |
| 44 | +let error = 0 |
| 45 | +const arr = [] |
| 46 | + |
| 47 | +function count (isSuccess, i, doh, result) { |
| 48 | + n++ |
| 49 | + if (isSuccess) { |
| 50 | + success++ |
| 51 | + arr[i] = `${doh.dnsServer} : ${hostname1} -> ${result.answers[0].data}`; |
| 52 | + } else error++ |
| 53 | + |
| 54 | + if (n === servers.length) { |
| 55 | + console.info(`\n\n=============================================================================\n全部测完:总计:${servers.length}, 成功:${success},失败:${error}`); |
| 56 | + for (const item of arr) { |
| 57 | + if (item) { |
| 58 | + console.info(item); |
| 59 | + } |
| 60 | + } |
| 61 | + console.info('=============================================================================\n\n') |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +for (let i = 0; i < servers.length; i++) { |
| 66 | + const n = i; |
| 67 | + const doh = new DNSOverHTTPS(`dns${i}`, null, null, servers[i], sni) |
| 68 | + doh._doDnsQuery(hostname1) |
| 69 | + .then((result) => { |
| 70 | + // console.info(`===> test testDoH '${doh.dnsServer}': ${hostname1} ->`, result.answers, '\n\n') |
| 71 | + count(true, n, doh, result) |
| 72 | + }) |
| 73 | + .catch((e) => { |
| 74 | + // console.error(`===> test testDoH '${doh.dnsServer}': ${hostname1} 失败:`, e, '\n\n') |
| 75 | + count(false) |
| 76 | + }) |
| 77 | +} |
0 commit comments