Skip to content

Commit 4e56d4d

Browse files
恢复预设IP功能
1 parent 4097a34 commit 4e56d4d

File tree

4 files changed

+6
-35
lines changed

4 files changed

+6
-35
lines changed

packages/mitmproxy/src/lib/dns/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ module.exports = class BaseDNS {
8484

8585
async _lookupInternal (hostname) {
8686
// 获取当前域名的预设IP列表
87-
let hostnamePreSetIpList = matchUtil.matchHostname(this.preSetIpList, hostname, 'matched preSetIpList')
87+
let hostnamePreSetIpList = matchUtil.matchHostname(this.preSetIpList, hostname, `matched preSetIpList(${this.dnsName})`)
8888
if (hostnamePreSetIpList && (hostnamePreSetIpList.length > 0 || hostnamePreSetIpList.length === undefined)) {
8989
if (hostnamePreSetIpList.length > 0) {
9090
hostnamePreSetIpList = hostnamePreSetIpList.slice()

packages/mitmproxy/src/lib/dns/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,14 @@ module.exports = {
6868
return dnsMap
6969
},
7070
hasDnsLookup (dnsConfig, hostname) {
71-
let providerName = null
72-
7371
// 先匹配 预设IP配置
74-
const hostnamePreSetIpList = matchUtil.matchHostname(dnsConfig.preSetIpList, hostname, 'matched preSetIpList')
72+
const hostnamePreSetIpList = matchUtil.matchHostname(dnsConfig.preSetIpList, hostname, 'matched preSetIpList(hasDnsLookup)')
7573
if (hostnamePreSetIpList) {
7674
return dnsConfig.dnsMap.PreSet
7775
}
7876

7977
// 再匹配 DNS映射配置
80-
providerName = matchUtil.matchHostname(dnsConfig.mapping, hostname, 'get dns providerName')
78+
const providerName = matchUtil.matchHostname(dnsConfig.mapping, hostname, 'get dns providerName')
8179

8280
// 由于DNS中的usa已重命名为cloudflare,所以做以下处理,为了向下兼容
8381
if (providerName === 'usa' && dnsConfig.dnsMap.usa == null && dnsConfig.dnsMap.cloudflare != null) {
Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,13 @@
1-
const matchUtil = require('../../utils/util.match')
21
const BaseDNS = require('./base')
32

4-
function mapToList (ipMap) {
5-
const ipList = []
6-
for (const key in ipMap) {
7-
if (ipMap[key]) { // 配置为 ture 时才生效
8-
ipList.push(key)
9-
}
10-
}
11-
return ipList
12-
}
13-
143
module.exports = class DNSOverPreSetIpList extends BaseDNS {
154
constructor (preSetIpList) {
16-
super()
17-
this.preSetIpList = preSetIpList
5+
super('PreSet', null, preSetIpList)
186
this.name = 'PreSet'
197
this.type = 'PreSet'
208
}
219

22-
async _lookup (hostname) {
23-
// 获取当前域名的预设IP列表
24-
let hostnamePreSetIpList = matchUtil.matchHostname(this.preSetIpList, hostname, 'matched preSetIpList')
25-
if (hostnamePreSetIpList && (hostnamePreSetIpList.length > 0 || hostnamePreSetIpList.length === undefined)) {
26-
if (hostnamePreSetIpList.length > 0) {
27-
hostnamePreSetIpList = hostnamePreSetIpList.slice()
28-
} else {
29-
hostnamePreSetIpList = mapToList(hostnamePreSetIpList)
30-
}
31-
32-
if (hostnamePreSetIpList.length > 0) {
33-
return hostnamePreSetIpList
34-
}
35-
}
36-
37-
// 未预设当前域名的IP列表
10+
async _lookup (_hostname) {
3811
return []
3912
}
4013
}

packages/mitmproxy/src/lib/speed/SpeedTester.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class SpeedTester {
7979
}
8080

8181
async getFromOneDns (dns) {
82-
return await dns._lookup(this.hostname)
82+
return await dns._lookupInternal(this.hostname)
8383
}
8484

8585
async test () {

0 commit comments

Comments
 (0)