mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 02:39:33 +02:00
server/server -> server/core
This commit is contained in:
parent
114327d4ce
commit
5a3d0650c9
838 changed files with 111 additions and 111 deletions
29
server/core/helpers/dns.ts
Normal file
29
server/core/helpers/dns.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import { lookup } from 'dns'
|
||||
import ipaddr 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 = ipaddr.parse(address)
|
||||
|
||||
if (parsed.range() !== 'unicast') return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
export {
|
||||
dnsLookupAll,
|
||||
isResolvingToUnicastOnly
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue