diff --git a/packages/mitmproxy/src/lib/dns/base.js b/packages/mitmproxy/src/lib/dns/base.js index d2dcf48e..386f30e5 100644 --- a/packages/mitmproxy/src/lib/dns/base.js +++ b/packages/mitmproxy/src/lib/dns/base.js @@ -22,7 +22,8 @@ class IpCache extends DynamicChoice { } module.exports = class BaseDNS { - constructor () { + constructor (dnsName) { + this.dnsName = dnsName this.cache = new LRUCache({ maxSize: cacheSize, sizeCalculation: () => { @@ -60,11 +61,11 @@ module.exports = class BaseDNS { ipList.push(hostname) // 把原域名加入到统计里去 ipCache.setBackupList(ipList) - log.info(`[DNS]: ${hostname} ➜ ${ipCache.value} (${new Date() - t} ms), ipList: ${JSON.stringify(ipList)}, ipCache:`, JSON.stringify(ipCache)) + log.info(`[DNS '${this.dnsName}']: ${hostname} ➜ ${ipCache.value} (${new Date() - t} ms), ipList: ${JSON.stringify(ipList)}, ipCache:`, JSON.stringify(ipCache)) return ipCache.value } catch (error) { - log.error(`[DNS] cannot resolve hostname ${hostname}, error:`, error) + log.error(`[DNS '${this.dnsName}'] cannot resolve hostname ${hostname}, error:`, error) return hostname } } diff --git a/packages/mitmproxy/src/lib/dns/https.js b/packages/mitmproxy/src/lib/dns/https.js index 3175da0f..85a936e9 100644 --- a/packages/mitmproxy/src/lib/dns/https.js +++ b/packages/mitmproxy/src/lib/dns/https.js @@ -18,8 +18,8 @@ function mapToList (ipMap) { } module.exports = class DNSOverHTTPS extends BaseDNS { - constructor (dnsServer, preSetIpList) { - super() + constructor (dnsName, dnsServer, preSetIpList) { + super(dnsName) this.dnsServer = dnsServer this.preSetIpList = preSetIpList } @@ -44,20 +44,21 @@ module.exports = class DNSOverHTTPS extends BaseDNS { const start = new Date() try { const result = await dohQueryAsync({ url: this.dnsServer }, [{ type: 'A', name: hostname }]) + const cost = new Date() - start if (result.answers.length === 0) { // 说明没有获取到ip - log.info('该域名没有ip地址解析:', hostname, ', cost:', (new Date() - start), 'ms') + log.info(`DNS '${this.dnsName}' 没有该域名的IP地址: ${hostname}, cost: ${cost} ms`) return [] } const ret = result.answers.filter(item => item.type === 'A').map(item => item.data) if (ret.length === 0) { - log.info('该域名没有IPv4地址解析:', hostname, ', cost:', (new Date() - start), 'ms') + log.info(`DNS '${this.dnsName}' 没有该域名的IPv4地址: ${hostname}, cost: ${cost} ms`) } else { - log.info('获取到域名地址:', hostname, JSON.stringify(ret), ', cost:', (new Date() - start), 'ms') + log.info(`DNS '${this.dnsName}' 获取到该域名的IPv4地址: ${hostname} ${JSON.stringify(ret)}, cost: ${cost} ms`) } return ret } catch (e) { - log.warn('DNS query error:', hostname, ', dns:', this.dnsServer, ', cost:', (new Date() - start), 'ms, error:', e) + log.warn(`DNS query error: ${hostname}, dns: ${this.dnsName}, dnsServer: ${this.dnsServer}, cost: ${new Date() - start} ms, error:`, e) return [] } } diff --git a/packages/mitmproxy/src/lib/dns/index.js b/packages/mitmproxy/src/lib/dns/index.js index 0e23f7a5..e153a0c9 100644 --- a/packages/mitmproxy/src/lib/dns/index.js +++ b/packages/mitmproxy/src/lib/dns/index.js @@ -13,11 +13,11 @@ module.exports = { const conf = dnsProviders[provider] if (conf.type === 'ipaddress') { - dnsMap[provider] = new DNSOverIpAddress(conf.server) + dnsMap[provider] = new DNSOverIpAddress(provider) } else if (conf.type === 'https') { - dnsMap[provider] = new DNSOverHTTPS(conf.server, preSetIpList) + dnsMap[provider] = new DNSOverHTTPS(provider, conf.server, preSetIpList) } else { - dnsMap[provider] = new DNSOverTLS(conf.server) + dnsMap[provider] = new DNSOverTLS(provider) } // 设置DNS名称到name属性中 diff --git a/packages/mitmproxy/src/lib/speed/SpeedTester.js b/packages/mitmproxy/src/lib/speed/SpeedTester.js index a5f915ea..8c8b06ea 100644 --- a/packages/mitmproxy/src/lib/speed/SpeedTester.js +++ b/packages/mitmproxy/src/lib/speed/SpeedTester.js @@ -62,7 +62,7 @@ class SpeedTester { for (const dnsKey in dnsMap) { const dns = dnsMap[dnsKey] const one = this.getFromOneDns(dns).then((ipList) => { - if (ipList) { + if (ipList && ipList.length > 0) { for (const ip of ipList) { ips[ip] = { dns: ipList.isPreSet === true ? '预设IP' : dnsKey } }