Skip to content

Commit

Permalink
feature: 支持IP预设置功能 (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangliang181230 authored Jul 8, 2024
1 parent 01e395c commit 5e6e7b2
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 50 deletions.
69 changes: 68 additions & 1 deletion packages/core/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -325,7 +392,7 @@ module.exports = {
enabled: true,
interval: 300000,
hostnameList: ['github.com'],
dnsProviders: ['safe360', 'cloudflare', 'rubyfish']
dnsProviders: ['cloudflare', 'safe360', 'rubyfish']
}
}
},
Expand Down
11 changes: 8 additions & 3 deletions packages/gui/src/view/pages/server.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@
</a-col>
</a-row>
</a-tab-pane>
<a-tab-pane tab="DNS设置" key="4">
<a-tab-pane tab="IP预设置" key="4">
<div>说明:IP预设置功能,需要与 `DNS设置` 或 `IP测速` 功能一起使用才会生效。</div>
<vue-json-editor style="height:100%;margin-top:10px;" ref="editor" v-model="config.server.preSetIpList" mode="code"
:show-btns="false" :expandedOnStart="true"></vue-json-editor>
</a-tab-pane>
<a-tab-pane tab="DNS设置" key="5">
<div>
<a-row style="margin-top:10px">
<a-col span="19">
Expand Down Expand Up @@ -118,7 +123,7 @@
</a-row>
</div>
</a-tab-pane>
<!-- <a-tab-pane tab="SNI" key="5">-->
<!-- <a-tab-pane tab="SNI" key="6">-->
<!-- <a-row style="margin-top:10px">-->
<!-- <a-col span="19">-->
<!-- <div>这里配置哪些域名要修改sni</div>-->
Expand All @@ -139,7 +144,7 @@
<!-- </a-col>-->
<!-- </a-row>-->
<!-- </a-tab-pane>-->
<a-tab-pane tab="IP测速" key="6">
<a-tab-pane tab="IP测速" key="7">
<div style="padding-right: 10px">
<a-alert type="info" message="对从dns获取到的ip进行测速,使用速度最快的ip进行访问。(对使用增强功能的域名没啥用)"></a-alert>
<a-form-item label="开启dns测速" :label-col="labelCol" :wrapper-col="wrapperCol">
Expand Down
50 changes: 8 additions & 42 deletions packages/mitmproxy/src/lib/dns/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -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服务器获取
Expand Down
4 changes: 2 additions & 2 deletions packages/mitmproxy/src/lib/dns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ 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]
if (conf.type === 'ipaddress') {
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
},
Expand Down
2 changes: 1 addition & 1 deletion packages/mitmproxy/src/lib/speed/SpeedTester.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/mitmproxy/src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down

0 comments on commit 5e6e7b2

Please sign in to comment.