diff --git a/api/dnsresolver.js b/api/dnsresolver.js index ecadb797..226e49d4 100644 --- a/api/dnsresolver.js +++ b/api/dnsresolver.js @@ -21,33 +21,70 @@ const dnsServers = { const dohServers = { 'Google': 'https://dns.google/resolve?', 'Cloudflare': 'https://cloudflare-dns.com/dns-query?ct=application/dns-json&', + 'AdGuard': 'https://dns.adguard.com/resolve?', 'AliDNS': 'https://dns.alidns.com/resolve?', }; -const resolveDns = async (hostname, name, server) => { +const resolveDns = async (hostname, type, name, server) => { const resolver = new Resolver(); resolver.setServers([server]); const resolve4Async = promisify(resolver.resolve4.bind(resolver)); + const resolve6Async = promisify(resolver.resolve6.bind(resolver)); + const resolveTxtAsync = promisify(resolver.resolveTxt.bind(resolver)); + const resolveCnameAsync = promisify(resolver.resolveCname.bind(resolver)); + const resolveNSAsync = promisify(resolver.resolveNs.bind(resolver)); + const resolveAnyAsync = promisify(resolver.resolveAny.bind(resolver)); try { - const addresses = await resolve4Async(hostname); + let addresses; + + // 根据传入的 type 参数选择不同的解析方法 + switch (type) { + case 'A': + addresses = await resolve4Async(hostname); + break; + case 'AAAA': + addresses = await resolve6Async(hostname); + break; + case 'TXT': + addresses = await resolveTxtAsync(hostname); + // TXT 记录解析的结果是一个二维数组,这里进行扁平化处理 + addresses = addresses.flat(); + break; + case 'CNAME': + addresses = await resolveCnameAsync(hostname); + break; + case 'NS': + addresses = await resolveNSAsync(hostname); + break; + default: + throw new Error('Unsupported type'); + } + + if (addresses.length === 0 || addresses === '' || addresses === null) { + return { [name]: `N/A` }; + } + return { [name]: addresses }; } catch (error) { console.log(error.message); - return { [name]: `Error: No addresses found` }; + return { [name]: `N/A` }; } }; -const resolveDoh = async (hostname, name, url) => { +const resolveDoh = async (hostname, type, name, url) => { try { - const response = await fetch(`${url}name=${hostname}&type=A`, { + const response = await fetch(`${url}name=${hostname}&type=${type}`, { headers: { 'Accept': 'application/dns-json' } }); const data = await response.json(); - const addresses = data.Answer ? data.Answer.map(answer => answer.data) : ['Error: No addresses found']; + const addresses = data.Answer ? data.Answer.map(answer => answer.data) : ['N/A']; + if (addresses.length === 0 || addresses === '' || addresses === null) { + return { [name]: `N/A` }; + } return { [name]: addresses }; } catch (error) { console.log(error.message); - return { [name]: `Error: No addresses found` }; + return { [name]: `N/A` }; } }; @@ -70,7 +107,7 @@ const dnsResolver = async (req, res) => { return res.status(403).json({ error: 'What are you doing?' }); } - const { hostname } = req.query; + const { hostname, type } = req.query; if (typeof hostname !== 'string') { return res.status(400).send({ error: 'Hostname parameter must be a string' }); @@ -84,8 +121,8 @@ const dnsResolver = async (req, res) => { return res.status(400).send({ error: 'Invalid hostname' }); } - const dnsPromises = Object.entries(dnsServers).map(([name, ip]) => resolveDns(hostname, name, ip)); - const dohPromises = Object.entries(dohServers).map(([name, url]) => resolveDoh(hostname, name, url)); + const dnsPromises = Object.entries(dnsServers).map(([name, ip]) => resolveDns(hostname, type, name, ip)); + const dohPromises = Object.entries(dohServers).map(([name, url]) => resolveDoh(hostname, type, name, url)); try { // 并行执行所有 DNS 和 DoH 查询 diff --git a/src/components/advancedtools.vue b/src/components/advancedtools.vue index cbfe50ea..71733e57 100644 --- a/src/components/advancedtools.vue +++ b/src/components/advancedtools.vue @@ -9,77 +9,24 @@

{{ $t('advancedtools.Note') }}

- -
-
-
-

🌐 {{ $t('pingtest.Title') }}

-

{{ $t('advancedtools.PingTestNote') }}

- +
+
+
+

{{ card.icon }} {{ $t(card.titleKey) }}

+

{{ $t(card.noteKey) }}

-
- ↓ -
+
- -
-
-
-

📡 {{ $t('mtrtest.Title') }}

-

{{ $t('advancedtools.MTRTestNote') }}

- -
-
- ↓ -
-
-
-
-
- -
-
-
-

🚏 {{ $t('ruletest.Title') }}

-

{{ $t('advancedtools.RuleTestNote') }}

- -
-
- ↓ -
-
-
-
-
- -
-
-
-

🔦 {{ $t('dnsresolver.Title') }}

-

{{ $t('advancedtools.DNSResolverNote') }}

- -
-
- ↓ -
-
-
-
-
-
-
-
+
@@ -110,14 +57,19 @@ export default { data() { return { - + cards: [ + { path: '/pingtest', icon: '🌐', titleKey: 'pingtest.Title', noteKey: 'advancedtools.PingTestNote' }, + { path: '/mtrtest', icon: '📡', titleKey: 'mtrtest.Title', noteKey: 'advancedtools.MTRTestNote' }, + { path: '/ruletest', icon: '🚏', titleKey: 'ruletest.Title', noteKey: 'advancedtools.RuleTestNote' }, + { path: '/dnsresolver', icon: '🔦', titleKey: 'dnsresolver.Title', noteKey: 'advancedtools.DNSResolverNote' }, + ] } }, methods: { navigateAndToggleOffcanvas(routePath) { this.$router.push(routePath); - switch(routePath) { + switch (routePath) { case '/pingtest': this.$trackEvent('Nav', 'NavClick', 'PingTest'); break; diff --git a/src/components/dnsresolver.vue b/src/components/dnsresolver.vue index 223d8b33..3bf3c35e 100644 --- a/src/components/dnsresolver.vue +++ b/src/components/dnsresolver.vue @@ -21,6 +21,19 @@ :placeholder="$t('dnsresolver.Placeholder')" v-model="queryURL" @keyup.enter="onSubmit" name="queryURL" id="queryURL" data-1p-ignore> + +
-
-
+
-
-
- -
diff --git a/src/components/mtrtest.vue b/src/components/mtrtest.vue index bce12f96..86cce34d 100644 --- a/src/components/mtrtest.vue +++ b/src/components/mtrtest.vue @@ -19,15 +19,13 @@
-
-
+
-
-
+ -
diff --git a/src/locales/en.json b/src/locales/en.json index da4d090c..a0448345 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -29,7 +29,8 @@ "invalidURL": "Invalid URL or Domain Name", "fetchError": "Unable to fetch resolution results", "Provider": "DNS Provider", - "Result": "Resolution Result" + "Result": "Resolution Result", + "Record": "Record" }, "ruletest": { "Title": "Rule Test", diff --git a/src/locales/fr.json b/src/locales/fr.json index d36f3133..6859c2cf 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -29,7 +29,8 @@ "invalidURL": "URL ou Nom de Domaine invalide", "fetchError": "Impossible de récupérer les résultats de résolution", "Provider": "Fournisseur DNS", - "Result": "Résultat de la Résolution" + "Result": "Résultat de la Résolution", + "Record": "Enregistrement" }, "ruletest": { "Title": "Test de règles", diff --git a/src/locales/zh.json b/src/locales/zh.json index 04e3c9db..bd91f4f6 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -29,7 +29,8 @@ "invalidURL": "无效的 URL 或域名", "fetchError": "无法获取解析结果", "Provider": "DNS 服务商", - "Result": "解析结果" + "Result": "解析结果", + "Record": "记录" }, "ruletest": { "Title": "分流测试",