]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/helpers/dns.ts
Correctly check import target URL IP
[github/Chocobozzz/PeerTube.git] / server / helpers / dns.ts
CommitLineData
f33e5159
C
1import { lookup } from 'dns'
2import { parse as parseIP } from 'ipaddr.js'
3
4function 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
14async 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
26export {
27 dnsLookupAll,
28 isResolvingToUnicastOnly
29}