From 5e6e7b288bff445b0d2f35719989078ad36bc741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com> Date: Mon, 8 Jul 2024 17:07:41 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=E6=94=AF=E6=8C=81IP=E9=A2=84?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=8A=9F=E8=83=BD=20(#321)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/config/index.js | 69 ++++++++++++++++++- packages/gui/src/view/pages/server.vue | 11 ++- packages/mitmproxy/src/lib/dns/https.js | 50 +++----------- packages/mitmproxy/src/lib/dns/index.js | 4 +- .../mitmproxy/src/lib/speed/SpeedTester.js | 2 +- packages/mitmproxy/src/options.js | 2 +- 6 files changed, 88 insertions(+), 50 deletions(-) diff --git a/packages/core/src/config/index.js b/packages/core/src/config/index.js index 2a30654a82..77f7255bc8 100644 --- a/packages/core/src/config/index.js +++ b/packages/core/src/config/index.js @@ -260,6 +260,73 @@ module.exports = { } } }, + // 预设置IP列表 + preSetIpList: { + 'github.com': [ + '20.26.156.215', + '20.27.177.113', + '20.87.245.0', + '20.200.245.247', + '20.201.28.151', + '20.205.243.166', + '20.248.137.48', + '140.82.113.3', + '140.82.114.4', + '140.82.116.4', + '140.82.121.3', + '140.82.121.4' + ], + 'api.github.com': [ + '20.26.156.210', + '20.27.177.116', + '20.87.245.6', + '20.200.245.245', + '20.201.28.148', + '20.205.243.168', + '20.248.137.49', + '140.82.112.5', + '140.82.113.6', + '140.82.116.6', + '140.82.121.6' + ], + 'codeload.github.com': [ + '20.26.156.216', + '20.27.177.114', + '20.87.245.7', + '20.200.245.246', + '20.201.28.149', + '20.205.243.165', + '20.248.137.55', + '140.82.113.9', + '140.82.114.10', + '140.82.116.10', + '140.82.121.9' + ], + '*.githubusercontent.com': [ + '185.199.108.133', + '185.199.109.133', + '185.199.110.133', + '185.199.111.133' + ], + 'github.githubassets.com': [ + '185.199.108.154', + '185.199.109.154', + '185.199.110.154', + '185.199.111.154' + ], + 'collector.github.com': ['0.0.0.0'], + 'github.io': [ + '185.199.108.153', + '185.199.109.153', + '185.199.110.153', + '185.199.111.153' + ], + 'hub.docker.com': [ + '44.221.37.199', + '52.44.227.212', + '54.156.140.159' + ] + }, whiteList: { '*.cn': true, 'cn.*': true, @@ -325,7 +392,7 @@ module.exports = { enabled: true, interval: 300000, hostnameList: ['github.com'], - dnsProviders: ['safe360', 'cloudflare', 'rubyfish'] + dnsProviders: ['cloudflare', 'safe360', 'rubyfish'] } } }, diff --git a/packages/gui/src/view/pages/server.vue b/packages/gui/src/view/pages/server.vue index c367e67352..24fcdd81c6 100644 --- a/packages/gui/src/view/pages/server.vue +++ b/packages/gui/src/view/pages/server.vue @@ -89,7 +89,12 @@ - + +
说明:IP预设置功能,需要与 `DNS设置` 或 `IP测速` 功能一起使用才会生效。
+ +
+
@@ -118,7 +123,7 @@
- + @@ -139,7 +144,7 @@ - +
diff --git a/packages/mitmproxy/src/lib/dns/https.js b/packages/mitmproxy/src/lib/dns/https.js index 4d0deb9c65..728e461441 100644 --- a/packages/mitmproxy/src/lib/dns/https.js +++ b/packages/mitmproxy/src/lib/dns/https.js @@ -3,55 +3,21 @@ const doh = require('dns-over-http') const BaseDNS = require('./base') const log = require('../../utils/util.log') const dohQueryAsync = promisify(doh.query) +const matchUtil = require('../../utils/util.match') module.exports = class DNSOverHTTPS extends BaseDNS { - constructor (dnsServer) { + constructor (dnsServer, preSetIpList) { super() this.dnsServer = dnsServer + this.preSetIpList = preSetIpList } async _lookup (hostname) { - // 直接判断域名是否为example.com - if (hostname === 'github.com') { - log.info('域名github.com使用内置IP集') - // 返回预设的IP地址集 - return ['140.82.114.4', '20.87.245.0', '20.27.177.113', '20.205.243.166', '20.248.137.48', '140.82.121.3', '140.82.116.4', '20.200.245.247', '20.26.156.215', '140.82.113.3', '140.82.121.4', '20.201.28.151'] - } - // 直接判断域名是否为example.com - if (hostname === 'api.github.com') { - log.info('域名api.github.com使用内置IP集') - // 返回预设的IP地址集 - return ['20.87.245.6', '140.82.112.5', '140.82.116.6', '20.26.156.210', '20.200.245.245', '20.27.177.116', '20.248.137.49', '20.201.28.148', '140.82.113.6', '20.205.243.168', '140.82.121.6'] - } - if (hostname === 'codeload.github.com') { - log.info('域名codeload.github.com使用内置IP集') - // 返回预设的IP地址集 - return ['20.27.177.114', '140.82.116.10', '140.82.114.10', '20.26.156.216', '20.87.245.7', '20.200.245.246', '20.248.137.55', '20.205.243.165', '20.201.28.149', '140.82.121.9', '140.82.113.9'] - } - if (hostname.match(/.*\.githubusercontent\.com$/)) { - log.info('域名githubusercontent及其子域使用内置IP集') - // 返回预设的IP地址集 - return ['185.199.111.133', '185.199.108.133', '185.199.109.133', '185.199.110.133'] - } - if (hostname === 'github.githubassets.com') { - log.info('域名github.githubassets.com使用内置IP集') - // 返回预设的IP地址集 - return ['185.199.110.154', '185.199.111.154', '185.199.109.154', '185.199.108.154'] - } - if (hostname === 'collector.github.com') { - log.info('域名collector.github.com已根据AdGuard DNS filter规则拦截') - // 返回预设的IP地址集 - return ['0.0.0.0'] - } - if (hostname === 'github.io') { - log.info('域名github.io使用内置IP集') - // 返回预设的IP地址集 - return ['185.199.108.153', '185.199.109.153', '185.199.111.153', '185.199.110.153'] - } - if (hostname === 'hub.docker.com') { - log.info('域名hub.docker.com使用内置IP集') - // 返回预设的IP地址集 - return ['54.156.140.159', '52.44.227.212', '44.221.37.199'] + // 获取当前域名的预设IP列表 + const hostnamePreSetIpList = matchUtil.matchHostname(this.preSetIpList, hostname, 'matched preSetIpList') + if (hostnamePreSetIpList && hostnamePreSetIpList.length > 0) { + hostnamePreSetIpList.isPreSet = true + return hostnamePreSetIpList } // 未预设当前域名的IP列表,则从dns服务器获取 diff --git a/packages/mitmproxy/src/lib/dns/index.js b/packages/mitmproxy/src/lib/dns/index.js index 7fdc6dabac..1fdcb81f63 100644 --- a/packages/mitmproxy/src/lib/dns/index.js +++ b/packages/mitmproxy/src/lib/dns/index.js @@ -4,7 +4,7 @@ const DNSOverIpAddress = require('./ipaddress.js') const matchUtil = require('../../utils/util.match') module.exports = { - initDNS (dnsProviders) { + initDNS (dnsProviders, preSetIpList) { const dnsMap = {} for (const provider in dnsProviders) { const conf = dnsProviders[provider] @@ -12,7 +12,7 @@ module.exports = { dnsMap[provider] = new DNSOverIpAddress(conf.server) continue } - dnsMap[provider] = conf.type === 'https' ? new DNSOverHTTPS(conf.server) : new DNSOverTLS(conf.server) + dnsMap[provider] = conf.type === 'https' ? new DNSOverHTTPS(conf.server, preSetIpList) : new DNSOverTLS(conf.server) } return dnsMap }, diff --git a/packages/mitmproxy/src/lib/speed/SpeedTester.js b/packages/mitmproxy/src/lib/speed/SpeedTester.js index 633b60c1d6..140b624c00 100644 --- a/packages/mitmproxy/src/lib/speed/SpeedTester.js +++ b/packages/mitmproxy/src/lib/speed/SpeedTester.js @@ -63,7 +63,7 @@ class SpeedTester { const one = this.getFromOneDns(dns).then(ipList => { if (ipList) { for (const ip of ipList) { - ips[ip] = { dns: dnsKey } + ips[ip] = { dns: ipList.isPreSet === true ? '预设IP' : dnsKey } } } }) diff --git a/packages/mitmproxy/src/options.js b/packages/mitmproxy/src/options.js index 7799891cdf..e9620278ba 100644 --- a/packages/mitmproxy/src/options.js +++ b/packages/mitmproxy/src/options.js @@ -48,7 +48,7 @@ module.exports = (config) => { host: serverConfig.host, port: serverConfig.port, dnsConfig: { - providers: dnsUtil.initDNS(serverConfig.dns.providers), + providers: dnsUtil.initDNS(serverConfig.dns.providers, matchUtil.domainMapRegexply(config.preSetIpList)), mapping: matchUtil.domainMapRegexply(dnsMapping), speedTest: config.dns.speedTest },