ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

30 lines
630 B

  1. import { lookup } from 'dns'
  2. import ipaddr from 'ipaddr.js'
  3. function dnsLookupAll (hostname: string) {
  4. return new Promise<string[]>((res, rej) => {
  5. lookup(hostname, { family: 0, all: true }, (err, adresses) => {
  6. if (err) return rej(err)
  7. return res(adresses.map(a => a.address))
  8. })
  9. })
  10. }
  11. async function isResolvingToUnicastOnly (hostname: string) {
  12. const addresses = await dnsLookupAll(hostname)
  13. for (const address of addresses) {
  14. const parsed = ipaddr.parse(address)
  15. if (parsed.range() !== 'unicast') return false
  16. }
  17. return true
  18. }
  19. export {
  20. dnsLookupAll,
  21. isResolvingToUnicastOnly
  22. }