修复dns查询问题
This commit is contained in:
@@ -25,9 +25,9 @@ export const toMD5 = str => crypto.createHash('md5').update(str).digest('hex')
|
||||
|
||||
const ipMap = new Map()
|
||||
export const getHostIp = hostname => {
|
||||
const ip = ipMap.get(hostname)
|
||||
if (typeof ip === 'string') return ip
|
||||
if (ip === true) return
|
||||
const result = ipMap.get(hostname)
|
||||
if (typeof result === 'object') return result
|
||||
if (result === true) return
|
||||
ipMap.set(hostname, true)
|
||||
// console.log(hostname)
|
||||
dns.lookup(hostname, {
|
||||
@@ -36,6 +36,13 @@ export const getHostIp = hostname => {
|
||||
}, (err, address, family) => {
|
||||
if (err) return console.log(err)
|
||||
// console.log(address, family)
|
||||
ipMap.set(hostname, address)
|
||||
ipMap.set(hostname, { address, family })
|
||||
})
|
||||
}
|
||||
|
||||
export const dnsLookup = (hostname, options, callback) => {
|
||||
const result = getHostIp(hostname)
|
||||
if (result) return callback(null, result.address, result.family)
|
||||
|
||||
dns.lookup(hostname, options, callback)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user