-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f7e5d58
commit e3e7710
Showing
7 changed files
with
64 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const BaseDNS = require('./base') | ||
const matchUtil = require('../../utils/util.match') | ||
|
||
function mapToList (ipMap) { | ||
const ipList = [] | ||
for (const key in ipMap) { | ||
if (!ipMap[key]) continue | ||
ipList.push(ipMap[key]) | ||
} | ||
return ipList | ||
} | ||
|
||
module.exports = class DNSOverPreSetIpList extends BaseDNS { | ||
constructor (preSetIpList) { | ||
super() | ||
this.preSetIpList = 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列表 | ||
return [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters