forked from michaljaz/webmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdns.js
More file actions
39 lines (37 loc) · 1.05 KB
/
dns.js
File metadata and controls
39 lines (37 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* global XMLHttpRequest */
// Custom DNS resolver made by SiebeDW. Powered by google dns.
// Supported: SRV (not all errors support)
module.exports.resolveSrv = function (hostname, callback) {
const Http = new XMLHttpRequest()
const url = `https://dns.google.com/resolve?name=${hostname}&type=SRV`
Http.open('GET', url)
Http.responseType = 'json'
Http.send()
Http.onload = function () {
const response = Http.response
if (response.Status === 3) {
const err = new Error('querySrv ENOTFOUND')
err.code = 'ENOTFOUND'
callback(err)
return
}
if (!response.Answer || response.Answer.length < 1) {
const err = new Error('querySrv ENODATA')
err.code = 'ENODATA'
callback(err)
return
}
const willreturn = []
response.Answer.forEach(function (object) {
const data = object.data.split(' ')
willreturn.push({
priority: data[0],
weight: data[1],
port: data[2],
name: data[3]
})
})
console.log(willreturn)
callback(null, willreturn)
}
}