支持IP预设使用CNAME,同时修正了来源显示错误的问题

pull/491/head
8odream 2025-06-14 01:08:01 +08:00
parent a19a73813c
commit 6d18a3ba09
2 changed files with 30 additions and 3 deletions

View File

@ -1,4 +1,5 @@
const LRUCache = require('lru-cache')
const net = require('node:net')
const log = require('../../utils/util.log.server')
const matchUtil = require('../../utils/util.match')
const { DynamicChoice } = require('../choice/index')
@ -94,9 +95,29 @@ module.exports = class BaseDNS {
}
if (hostnamePreSetIpList.length > 0) {
hostnamePreSetIpList.isPreSet = true
log.info(`[DNS-over-${this.dnsType} '${this.dnsName}'] 获取到该域名的预设IP列表 ${hostname} - ${JSON.stringify(hostnamePreSetIpList)}`)
return hostnamePreSetIpList
const result = []
for (const item of 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
}
}
}

View File

@ -80,11 +80,13 @@ class SpeedTester {
async getFromOneDns (dns) {
const results = []
let isPreSet = false
// 优先尝试IPv6查询
try {
const ipv6Result = await dns._lookupInternal(this.hostname, { family: 6 })
if (ipv6Result && ipv6Result.length > 0) {
isPreSet = ipv6Result.isPreSet === true
// 标准化IPv6地址格式
const standardized = ipv6Result.map(ip => {
// 确保IPv6地址格式统一
@ -103,12 +105,16 @@ class SpeedTester {
try {
const ipv4Result = await dns._lookupInternal(this.hostname)
if (ipv4Result) {
isPreSet = isPreSet || ipv4Result.isPreSet === true
results.push(...ipv4Result)
}
} catch (e) {
// IPv4查询失败
}
if (isPreSet) {
results.isPreSet = true
}
return results
}