aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/dns.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/server/helpers/dns.ts b/server/helpers/dns.ts
new file mode 100644
index 000000000..da8b666c2
--- /dev/null
+++ b/server/helpers/dns.ts
@@ -0,0 +1,29 @@
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}