refactor: 1

pull/180/head
xiaojunnuo@qq.com 2020-11-09 10:01:58 +08:00
parent 091cbc5336
commit 6125895ae6
1 changed files with 16 additions and 11 deletions

View File

@ -11,18 +11,23 @@ module.exports = class DNSOverHTTPS extends BaseDNS {
} }
async _lookup (hostname) { async _lookup (hostname) {
const result = await dohQueryAsync({ url: this.dnsServer }, [{ type: 'A', name: hostname }]) try {
if (result.answers.length === 0) { const result = await dohQueryAsync({ url: this.dnsServer }, [{ type: 'A', name: hostname }])
// 说明没有获取到ip if (result.answers.length === 0) {
console.log('该域名没有ip地址解析', hostname) // 说明没有获取到ip
console.log('该域名没有ip地址解析', hostname)
return []
}
const ret = result.answers.filter(item => { return item.type === 'A' }).map(item => { return item.data })
if (ret.length === 0) {
console.log('该域名没有ipv4地址解析', hostname)
} else {
console.log('获取到域名地址:', hostname, JSON.stringify(ret))
}
return ret
} catch (err) {
console.log('dns query error', hostname, err)
return [] return []
} }
const ret = result.answers.filter(item => { return item.type === 'A' }).map(item => { return item.data })
if (ret.length === 0) {
console.log('该域名没有ipv4地址解析', hostname)
} else {
console.log('获取到域名地址:', hostname, JSON.stringify(ret))
}
return ret
} }
} }