diff --git a/packages/mitmproxy/src/lib/dns/base.js b/packages/mitmproxy/src/lib/dns/base.js index 6a745c6..3ee308c 100644 --- a/packages/mitmproxy/src/lib/dns/base.js +++ b/packages/mitmproxy/src/lib/dns/base.js @@ -1,4 +1,5 @@ const LRUCache = require('lru-cache') +const net = require('node:net') const log = require('../../utils/util.log.server') const matchUtil = require('../../utils/util.match') const { DynamicChoice } = require('../choice/index') @@ -94,9 +95,29 @@ module.exports = class BaseDNS { } if (hostnamePreSetIpList.length > 0) { - hostnamePreSetIpList.isPreSet = true - log.info(`[DNS-over-${this.dnsType} '${this.dnsName}'] 获取到该域名的预设IP列表: ${hostname} - ${JSON.stringify(hostnamePreSetIpList)}`) - return hostnamePreSetIpList + const result = [] + for (const item of hostnamePreSetIpList) { + if (net.isIP(item)) { + // 如果是IP地址,直接使用 + result.push(item) + } else { + // 如果是域名,进行DNS解析 + try { + const resolved = await this._lookup(item, options) + if (resolved && resolved.length > 0) { + result.push(...resolved) + } + } catch (e) { + log.error(`[DNS-over-${this.dnsType} '${this.dnsName}'] 解析预设域名失败: ${item}`, e) + } + } + } + + if (result.length > 0) { + result.isPreSet = true + log.info(`[DNS-over-${this.dnsType} '${this.dnsName}'] 获取到该域名的预设IP列表: ${hostname} - ${JSON.stringify(result)}`) + return result + } } } diff --git a/packages/mitmproxy/src/lib/speed/SpeedTester.js b/packages/mitmproxy/src/lib/speed/SpeedTester.js index c781e99..0ac40ad 100644 --- a/packages/mitmproxy/src/lib/speed/SpeedTester.js +++ b/packages/mitmproxy/src/lib/speed/SpeedTester.js @@ -80,11 +80,13 @@ class SpeedTester { async getFromOneDns (dns) { const results = [] + let isPreSet = false // 优先尝试IPv6查询 try { const ipv6Result = await dns._lookupInternal(this.hostname, { family: 6 }) if (ipv6Result && ipv6Result.length > 0) { + isPreSet = ipv6Result.isPreSet === true // 标准化IPv6地址格式 const standardized = ipv6Result.map(ip => { // 确保IPv6地址格式统一 @@ -103,12 +105,16 @@ class SpeedTester { try { const ipv4Result = await dns._lookupInternal(this.hostname) if (ipv4Result) { + isPreSet = isPreSet || ipv4Result.isPreSet === true results.push(...ipv4Result) } } catch (e) { // IPv4查询失败 } + if (isPreSet) { + results.isPreSet = true + } return results }