From 4e56d4dc2c0908a72eeb5f99bb81ff2e5943aec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Tue, 4 Mar 2025 00:30:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=81=A2=E5=A4=8D=E9=A2=84=E8=AE=BEIP=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/mitmproxy/src/lib/dns/base.js | 2 +- packages/mitmproxy/src/lib/dns/index.js | 6 ++-- packages/mitmproxy/src/lib/dns/preset.js | 31 ++----------------- .../mitmproxy/src/lib/speed/SpeedTester.js | 2 +- 4 files changed, 6 insertions(+), 35 deletions(-) diff --git a/packages/mitmproxy/src/lib/dns/base.js b/packages/mitmproxy/src/lib/dns/base.js index b7413a9..a8718df 100644 --- a/packages/mitmproxy/src/lib/dns/base.js +++ b/packages/mitmproxy/src/lib/dns/base.js @@ -84,7 +84,7 @@ module.exports = class BaseDNS { async _lookupInternal (hostname) { // 获取当前域名的预设IP列表 - let hostnamePreSetIpList = matchUtil.matchHostname(this.preSetIpList, hostname, 'matched preSetIpList') + let hostnamePreSetIpList = matchUtil.matchHostname(this.preSetIpList, hostname, `matched preSetIpList(${this.dnsName})`) if (hostnamePreSetIpList && (hostnamePreSetIpList.length > 0 || hostnamePreSetIpList.length === undefined)) { if (hostnamePreSetIpList.length > 0) { hostnamePreSetIpList = hostnamePreSetIpList.slice() diff --git a/packages/mitmproxy/src/lib/dns/index.js b/packages/mitmproxy/src/lib/dns/index.js index d8103f1..b285a9f 100644 --- a/packages/mitmproxy/src/lib/dns/index.js +++ b/packages/mitmproxy/src/lib/dns/index.js @@ -68,16 +68,14 @@ module.exports = { return dnsMap }, hasDnsLookup (dnsConfig, hostname) { - let providerName = null - // 先匹配 预设IP配置 - const hostnamePreSetIpList = matchUtil.matchHostname(dnsConfig.preSetIpList, hostname, 'matched preSetIpList') + const hostnamePreSetIpList = matchUtil.matchHostname(dnsConfig.preSetIpList, hostname, 'matched preSetIpList(hasDnsLookup)') if (hostnamePreSetIpList) { return dnsConfig.dnsMap.PreSet } // 再匹配 DNS映射配置 - providerName = matchUtil.matchHostname(dnsConfig.mapping, hostname, 'get dns providerName') + const providerName = matchUtil.matchHostname(dnsConfig.mapping, hostname, 'get dns providerName') // 由于DNS中的usa已重命名为cloudflare,所以做以下处理,为了向下兼容 if (providerName === 'usa' && dnsConfig.dnsMap.usa == null && dnsConfig.dnsMap.cloudflare != null) { diff --git a/packages/mitmproxy/src/lib/dns/preset.js b/packages/mitmproxy/src/lib/dns/preset.js index 37b86e3..4d39ec0 100644 --- a/packages/mitmproxy/src/lib/dns/preset.js +++ b/packages/mitmproxy/src/lib/dns/preset.js @@ -1,40 +1,13 @@ -const matchUtil = require('../../utils/util.match') const BaseDNS = require('./base') -function mapToList (ipMap) { - const ipList = [] - for (const key in ipMap) { - if (ipMap[key]) { // 配置为 ture 时才生效 - ipList.push(key) - } - } - return ipList -} - module.exports = class DNSOverPreSetIpList extends BaseDNS { constructor (preSetIpList) { - super() - this.preSetIpList = preSetIpList + super('PreSet', null, preSetIpList) this.name = 'PreSet' this.type = 'PreSet' } - async _lookup (hostname) { - // 获取当前域名的预设IP列表 - let hostnamePreSetIpList = matchUtil.matchHostname(this.preSetIpList, hostname, 'matched preSetIpList') - if (hostnamePreSetIpList && (hostnamePreSetIpList.length > 0 || hostnamePreSetIpList.length === undefined)) { - if (hostnamePreSetIpList.length > 0) { - hostnamePreSetIpList = hostnamePreSetIpList.slice() - } else { - hostnamePreSetIpList = mapToList(hostnamePreSetIpList) - } - - if (hostnamePreSetIpList.length > 0) { - return hostnamePreSetIpList - } - } - - // 未预设当前域名的IP列表 + async _lookup (_hostname) { return [] } } diff --git a/packages/mitmproxy/src/lib/speed/SpeedTester.js b/packages/mitmproxy/src/lib/speed/SpeedTester.js index fc35825..59f4995 100644 --- a/packages/mitmproxy/src/lib/speed/SpeedTester.js +++ b/packages/mitmproxy/src/lib/speed/SpeedTester.js @@ -79,7 +79,7 @@ class SpeedTester { } async getFromOneDns (dns) { - return await dns._lookup(this.hostname) + return await dns._lookupInternal(this.hostname) } async test () {