mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-11-29 03:53:59 -06:00
30 lines
639 B
TypeScript
30 lines
639 B
TypeScript
|
import { lookup } from 'dns'
|
||
|
import { parse as parseIP } from 'ipaddr.js'
|
||
|
|
||
|
function dnsLookupAll (hostname: string) {
|
||
|
return new Promise<string[]>((res, rej) => {
|
||
|
lookup(hostname, { family: 0, all: true }, (err, adresses) => {
|
||
|
if (err) return rej(err)
|
||
|
|
||
|
return res(adresses.map(a => a.address))
|
||
|
})
|
||
|
})
|
||
|
}
|
||
|
|
||
|
async function isResolvingToUnicastOnly (hostname: string) {
|
||
|
const addresses = await dnsLookupAll(hostname)
|
||
|
|
||
|
for (const address of addresses) {
|
||
|
const parsed = parseIP(address)
|
||
|
|
||
|
if (parsed.range() !== 'unicast') return false
|
||
|
}
|
||
|
|
||
|
return true
|
||
|
}
|
||
|
|
||
|
export {
|
||
|
dnsLookupAll,
|
||
|
isResolvingToUnicastOnly
|
||
|
}
|