支持IP预设使用CNAME,同时修正了来源显示错误的问题
parent
a19a73813c
commit
6d18a3ba09
|
@ -1,4 +1,5 @@
|
||||||
const LRUCache = require('lru-cache')
|
const LRUCache = require('lru-cache')
|
||||||
|
const net = require('node:net')
|
||||||
const log = require('../../utils/util.log.server')
|
const log = require('../../utils/util.log.server')
|
||||||
const matchUtil = require('../../utils/util.match')
|
const matchUtil = require('../../utils/util.match')
|
||||||
const { DynamicChoice } = require('../choice/index')
|
const { DynamicChoice } = require('../choice/index')
|
||||||
|
@ -94,9 +95,29 @@ module.exports = class BaseDNS {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hostnamePreSetIpList.length > 0) {
|
if (hostnamePreSetIpList.length > 0) {
|
||||||
hostnamePreSetIpList.isPreSet = true
|
const result = []
|
||||||
log.info(`[DNS-over-${this.dnsType} '${this.dnsName}'] 获取到该域名的预设IP列表: ${hostname} - ${JSON.stringify(hostnamePreSetIpList)}`)
|
for (const item of hostnamePreSetIpList) {
|
||||||
return hostnamePreSetIpList
|
if (net.isIP(item)) {
|
||||||
|
// 如果是IP地址,直接使用
|
||||||
|
result.push(item)
|
||||||
|
} else {
|
||||||
|
// 如果是域名,进行DNS解析
|
||||||
|
try {
|
||||||
|
const resolved = await this._lookup(item, options)
|
||||||
|
if (resolved && resolved.length > 0) {
|
||||||
|
result.push(...resolved)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.error(`[DNS-over-${this.dnsType} '${this.dnsName}'] 解析预设域名失败: ${item}`, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.length > 0) {
|
||||||
|
result.isPreSet = true
|
||||||
|
log.info(`[DNS-over-${this.dnsType} '${this.dnsName}'] 获取到该域名的预设IP列表: ${hostname} - ${JSON.stringify(result)}`)
|
||||||
|
return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,11 +80,13 @@ class SpeedTester {
|
||||||
|
|
||||||
async getFromOneDns (dns) {
|
async getFromOneDns (dns) {
|
||||||
const results = []
|
const results = []
|
||||||
|
let isPreSet = false
|
||||||
|
|
||||||
// 优先尝试IPv6查询
|
// 优先尝试IPv6查询
|
||||||
try {
|
try {
|
||||||
const ipv6Result = await dns._lookupInternal(this.hostname, { family: 6 })
|
const ipv6Result = await dns._lookupInternal(this.hostname, { family: 6 })
|
||||||
if (ipv6Result && ipv6Result.length > 0) {
|
if (ipv6Result && ipv6Result.length > 0) {
|
||||||
|
isPreSet = ipv6Result.isPreSet === true
|
||||||
// 标准化IPv6地址格式
|
// 标准化IPv6地址格式
|
||||||
const standardized = ipv6Result.map(ip => {
|
const standardized = ipv6Result.map(ip => {
|
||||||
// 确保IPv6地址格式统一
|
// 确保IPv6地址格式统一
|
||||||
|
@ -103,12 +105,16 @@ class SpeedTester {
|
||||||
try {
|
try {
|
||||||
const ipv4Result = await dns._lookupInternal(this.hostname)
|
const ipv4Result = await dns._lookupInternal(this.hostname)
|
||||||
if (ipv4Result) {
|
if (ipv4Result) {
|
||||||
|
isPreSet = isPreSet || ipv4Result.isPreSet === true
|
||||||
results.push(...ipv4Result)
|
results.push(...ipv4Result)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// IPv4查询失败
|
// IPv4查询失败
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isPreSet) {
|
||||||
|
results.isPreSet = true
|
||||||
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue