]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/helpers/dns.ts
Fix s3 mock cleanup
[github/Chocobozzz/PeerTube.git] / server / helpers / dns.ts
1 import { lookup } from 'dns'
2 import { parse as parseIP } from 'ipaddr.js'
3
4 function dnsLookupAll (hostname: string) {
5 return new Promise<string[]>((res, rej) => {
6 lookup(hostname, { family: 0, all: true }, (err, adresses) => {
7 if (err) return rej(err)
8
9 return res(adresses.map(a => a.address))
10 })
11 })
12 }
13
14 async function isResolvingToUnicastOnly (hostname: string) {
15 const addresses = await dnsLookupAll(hostname)
16
17 for (const address of addresses) {
18 const parsed = parseIP(address)
19
20 if (parsed.range() !== 'unicast') return false
21 }
22
23 return true
24 }
25
26 export {
27 dnsLookupAll,
28 isResolvingToUnicastOnly
29 }