dns2 2.0.0 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +16 -0
- package/.github/FUNDING.yml +12 -12
- package/.github/workflows/lint.js.yml +17 -0
- package/.github/workflows/node.js.yml +29 -30
- package/LICENSE +18 -18
- package/README.md +227 -196
- package/SECURITY.md +21 -21
- package/client/doh.js +50 -42
- package/client/google.js +27 -27
- package/client/tcp.js +34 -34
- package/client/udp.js +39 -39
- package/example/client/doh.js +12 -12
- package/example/client/google.js +7 -8
- package/example/client/tcp-custom-dns.js +10 -10
- package/example/client/tcp.js +12 -12
- package/example/client/udp-custom-dns.js +11 -11
- package/example/client/udp-default.js +8 -8
- package/example/client/udp-subnet.js +11 -11
- package/example/client/udp.js +8 -8
- package/example/server/dns.js +46 -0
- package/example/server/doh.js +30 -28
- package/example/server/secret.key +28 -28
- package/example/server/server.crt +22 -22
- package/example/server/tcp.js +19 -19
- package/example/server/udp.js +23 -23
- package/index.js +97 -89
- package/lib/reader.js +53 -55
- package/lib/writer.js +42 -42
- package/package.json +42 -34
- package/packet.js +873 -857
- package/server/dns.js +94 -0
- package/server/doh.js +146 -143
- package/server/index.js +31 -24
- package/server/tcp.js +34 -26
- package/server/udp.js +47 -41
- package/test/index.js +395 -244
- package/test/test.js +34 -27
- package/.travis.yml +0 -4
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
-----BEGIN CERTIFICATE-----
|
|
2
|
-
MIIDqzCCApOgAwIBAgIUaX6RpRwOKLTEniFdAq5WadU33jUwDQYJKoZIhvcNAQEL
|
|
3
|
-
BQAwZTELMAkGA1UEBhMCU0UxEjAQBgNVBAgMCVN0b2NraG9sbTEPMA0GA1UEBwwG
|
|
4
|
-
VmFybWRvMR0wGwYDVQQKDBRub2RlLWRucyBkb2ggZXhhbXBsZTESMBAGA1UEAwwJ
|
|
5
|
-
bG9jYWxob3N0MB4XDTIwMTIyOTE2NDAxOVoXD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UyVLsaW4kevHXC/Mii
|
|
14
|
+
fQIDAQABo1MwUTAdBgNVHQ4EFgQUTHzmfH502gXcq7ouYT0hlhtdEIgwHwYDVR0j
|
|
15
|
+
BBgwFoAUTHzmfH502gXcq7ouYT0hlhtdEIgwDwYDVR0TAQH/BAUwAwEB/zANBgkq
|
|
16
|
+
hkiG9w0BAQsFAAOCAQEAG+hS41BD9U84mTHvy5F/bF1h3jqeLPZ4asWM3f3XZmHb
|
|
17
|
+
MVnASBnVySesjLvkn3FCB1nVm6sR+71l9qOn2E/2OSOliFejqtEwjrtUujTHx88V
|
|
18
|
+
fmnu0zKCo9j7itl12eBqr7hEE4PYEIOG46eyj70U75PxevTF6Ahp3IpSRQxmS/b2
|
|
19
|
+
mtMfhEJKyFYzQyI0Nx1ZZT/N0Vn45Ezgu0skggw0d2/3Y7h9573uKJPT8O4c+wRB
|
|
20
|
+
1VAEo5h+DTzjalNkiQubrtXS9aAplTmafjPHJyvTCZKqczGD6P/kvX1lI69L3pGG
|
|
21
|
+
lmIEBb2xjOuxxDGKiwuBqKb2pRIMfP8UtT/LxqQx4Q==
|
|
22
|
+
-----END CERTIFICATE-----
|
package/example/server/tcp.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
const dns = require('../..');
|
|
2
|
-
|
|
3
|
-
const { Packet } = dns;
|
|
4
|
-
|
|
5
|
-
const server = dns.createTCPServer();
|
|
6
|
-
|
|
7
|
-
server.on('request', (request, send, client) => {
|
|
8
|
-
const response = Packet.createResponseFromRequest(request);
|
|
9
|
-
const answer =
|
|
10
|
-
target: 'hermes2.jabber.org',
|
|
11
|
-
port: 8080,
|
|
12
|
-
weight: 30,
|
|
13
|
-
priority: 30
|
|
14
|
-
});
|
|
15
|
-
response.answers.push(answer);
|
|
16
|
-
send(response);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
server.listen(5333);
|
|
1
|
+
const dns = require('../..');
|
|
2
|
+
|
|
3
|
+
const { Packet } = dns;
|
|
4
|
+
|
|
5
|
+
const server = dns.createTCPServer();
|
|
6
|
+
|
|
7
|
+
server.on('request', (request, send, client) => {
|
|
8
|
+
const response = Packet.createResponseFromRequest(request);
|
|
9
|
+
const answer = Packet.createResourceFromQuestion(request.questions[0], {
|
|
10
|
+
target : 'hermes2.jabber.org',
|
|
11
|
+
port : 8080,
|
|
12
|
+
weight : 30,
|
|
13
|
+
priority : 30,
|
|
14
|
+
});
|
|
15
|
+
response.answers.push(answer);
|
|
16
|
+
send(response);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
server.listen(5333);
|
package/example/server/udp.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
const dns = require('../..');
|
|
2
|
-
|
|
3
|
-
const { Packet } = dns;
|
|
4
|
-
|
|
5
|
-
const server = dns.createUDPServer((request, send, rinfo) => {
|
|
6
|
-
const response = Packet.createResponseFromRequest(request);
|
|
7
|
-
const [ question ] = request.questions;
|
|
8
|
-
const { name } = question;
|
|
9
|
-
response.answers.push({
|
|
10
|
-
name,
|
|
11
|
-
type: Packet.TYPE.A,
|
|
12
|
-
class: Packet.CLASS.IN,
|
|
13
|
-
ttl: 300,
|
|
14
|
-
address: '8.8.8.8'
|
|
15
|
-
});
|
|
16
|
-
send(response);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
server.on('request', (request, response, rinfo) => {
|
|
20
|
-
console.log(request.header.id, request.questions[0]);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
server.listen(5333);
|
|
1
|
+
const dns = require('../..');
|
|
2
|
+
|
|
3
|
+
const { Packet } = dns;
|
|
4
|
+
|
|
5
|
+
const server = dns.createUDPServer((request, send, rinfo) => {
|
|
6
|
+
const response = Packet.createResponseFromRequest(request);
|
|
7
|
+
const [ question ] = request.questions;
|
|
8
|
+
const { name } = question;
|
|
9
|
+
response.answers.push({
|
|
10
|
+
name,
|
|
11
|
+
type : Packet.TYPE.A,
|
|
12
|
+
class : Packet.CLASS.IN,
|
|
13
|
+
ttl : 300,
|
|
14
|
+
address : '8.8.8.8',
|
|
15
|
+
});
|
|
16
|
+
send(response);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
server.on('request', (request, response, rinfo) => {
|
|
20
|
+
console.log(request.header.id, request.questions[0]);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
server.listen(5333);
|
package/index.js
CHANGED
|
@@ -1,89 +1,97 @@
|
|
|
1
|
-
const {
|
|
2
|
-
TCPServer,
|
|
3
|
-
UDPServer,
|
|
4
|
-
DOHServer,
|
|
5
|
-
createTCPServer,
|
|
6
|
-
createUDPServer,
|
|
7
|
-
createDOHServer,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
* @docs https://tools.ietf.org/html/
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
*
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return this.
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return this.resolve(domain, '
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
DNS.
|
|
82
|
-
DNS.
|
|
83
|
-
DNS.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
DNS.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
1
|
+
const {
|
|
2
|
+
TCPServer,
|
|
3
|
+
UDPServer,
|
|
4
|
+
DOHServer,
|
|
5
|
+
createTCPServer,
|
|
6
|
+
createUDPServer,
|
|
7
|
+
createDOHServer,
|
|
8
|
+
createServer,
|
|
9
|
+
} = require('./server');
|
|
10
|
+
const EventEmitter = require('events');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* [DNS description]
|
|
14
|
+
* @docs https://tools.ietf.org/html/rfc1034
|
|
15
|
+
* @docs https://tools.ietf.org/html/rfc1035
|
|
16
|
+
*/
|
|
17
|
+
class DNS extends EventEmitter {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
super();
|
|
20
|
+
Object.assign(this, {
|
|
21
|
+
port : 53,
|
|
22
|
+
retries : 3,
|
|
23
|
+
timeout : 3,
|
|
24
|
+
recursive : true,
|
|
25
|
+
resolverProtocol : 'UDP',
|
|
26
|
+
nameServers : [
|
|
27
|
+
'8.8.8.8',
|
|
28
|
+
'114.114.114.114',
|
|
29
|
+
],
|
|
30
|
+
rootServers: [
|
|
31
|
+
'a', 'b', 'c', 'd', 'e', 'f',
|
|
32
|
+
'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
|
33
|
+
].map(x => `${x}.root-servers.net`),
|
|
34
|
+
}, options);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* query
|
|
39
|
+
* @param {*} questions
|
|
40
|
+
*/
|
|
41
|
+
query(name, type, cls, clientIp) {
|
|
42
|
+
const { port, nameServers, recursive, resolverProtocol = 'UDP' } = this;
|
|
43
|
+
const createResolver = DNS[resolverProtocol + 'Client'];
|
|
44
|
+
return Promise.race(nameServers.map(address => {
|
|
45
|
+
const resolve = createResolver({ dns: address, port, recursive });
|
|
46
|
+
return resolve(name, type, cls, clientIp);
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* resolve
|
|
52
|
+
* @param {*} domain
|
|
53
|
+
* @param {*} type
|
|
54
|
+
* @param {*} cls
|
|
55
|
+
*/
|
|
56
|
+
resolve(domain, type = 'ANY', cls = DNS.Packet.CLASS.IN, clientIp = undefined) {
|
|
57
|
+
return this.query(domain, type, cls, clientIp);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
resolveA(domain, clientIp) {
|
|
61
|
+
return this.resolve(domain, 'A', undefined, clientIp);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
resolveAAAA(domain) {
|
|
65
|
+
return this.resolve(domain, 'AAAA');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
resolveMX(domain) {
|
|
69
|
+
return this.resolve(domain, 'MX');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
resolveCNAME(domain) {
|
|
73
|
+
return this.resolve(domain, 'CNAME');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
resolvePTR(domain) {
|
|
77
|
+
return this.resolve(domain, 'PTR');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
DNS.TCPServer = TCPServer;
|
|
82
|
+
DNS.UDPServer = UDPServer;
|
|
83
|
+
DNS.DOHServer = DOHServer;
|
|
84
|
+
|
|
85
|
+
DNS.createUDPServer = createUDPServer;
|
|
86
|
+
DNS.createTCPServer = createTCPServer;
|
|
87
|
+
DNS.createDOHServer = createDOHServer;
|
|
88
|
+
DNS.createServer = createServer;
|
|
89
|
+
|
|
90
|
+
DNS.TCPClient = require('./client/tcp');
|
|
91
|
+
DNS.DOHClient = require('./client/doh');
|
|
92
|
+
DNS.UDPClient = require('./client/udp');
|
|
93
|
+
DNS.GoogleClient = require('./client/google');
|
|
94
|
+
|
|
95
|
+
DNS.Packet = require('./packet');
|
|
96
|
+
|
|
97
|
+
module.exports = DNS;
|
package/lib/reader.js
CHANGED
|
@@ -1,55 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* [Reader description]
|
|
4
|
-
* @param {[type]} buffer [description]
|
|
5
|
-
* @param {[type]} offset [description]
|
|
6
|
-
*/
|
|
7
|
-
function BufferReader(buffer, offset){
|
|
8
|
-
this.buffer = buffer;
|
|
9
|
-
this.offset = offset || 0;
|
|
10
|
-
return this;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* [read description]
|
|
15
|
-
* @param {[type]} buffer [description]
|
|
16
|
-
* @param {[type]} offset [description]
|
|
17
|
-
* @param {[type]} length [description]
|
|
18
|
-
* @return {[type]} [description]
|
|
19
|
-
*/
|
|
20
|
-
BufferReader.read = function(buffer, offset, length){
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function t(n){
|
|
26
|
-
|
|
27
|
-
for (
|
|
28
|
-
r[7 - i] = n & Math.pow(2, i) ? 1 : 0;
|
|
29
|
-
}
|
|
30
|
-
a = a.concat(r);
|
|
31
|
-
}
|
|
32
|
-
function p(a){
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
for(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
* [
|
|
45
|
-
* @
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
BufferReader.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
module.exports = BufferReader;
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* [Reader description]
|
|
4
|
+
* @param {[type]} buffer [description]
|
|
5
|
+
* @param {[type]} offset [description]
|
|
6
|
+
*/
|
|
7
|
+
function BufferReader(buffer, offset) {
|
|
8
|
+
this.buffer = buffer;
|
|
9
|
+
this.offset = offset || 0;
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* [read description]
|
|
15
|
+
* @param {[type]} buffer [description]
|
|
16
|
+
* @param {[type]} offset [description]
|
|
17
|
+
* @param {[type]} length [description]
|
|
18
|
+
* @return {[type]} [description]
|
|
19
|
+
*/
|
|
20
|
+
BufferReader.read = function(buffer, offset, length) {
|
|
21
|
+
let a = [];
|
|
22
|
+
let c = Math.ceil(length / 8);
|
|
23
|
+
let l = Math.floor(offset / 8);
|
|
24
|
+
const m = offset % 8;
|
|
25
|
+
function t(n) {
|
|
26
|
+
const r = [ 0, 0, 0, 0, 0, 0, 0, 0 ];
|
|
27
|
+
for (let i = 7; i >= 0; i--) {
|
|
28
|
+
r[7 - i] = n & Math.pow(2, i) ? 1 : 0;
|
|
29
|
+
}
|
|
30
|
+
a = a.concat(r);
|
|
31
|
+
}
|
|
32
|
+
function p(a) {
|
|
33
|
+
let n = 0;
|
|
34
|
+
const f = a.length - 1;
|
|
35
|
+
for (let i = f; i >= 0; i--) { if (a[f - i]) n += Math.pow(2, i); }
|
|
36
|
+
return n;
|
|
37
|
+
}
|
|
38
|
+
while (c--) t(buffer.readUInt8(l++));
|
|
39
|
+
return p(a.slice(m, m + length));
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* [read description]
|
|
44
|
+
* @param {[type]} size [description]
|
|
45
|
+
* @return {[type]} [description]
|
|
46
|
+
*/
|
|
47
|
+
BufferReader.prototype.read = function(size) {
|
|
48
|
+
const val = BufferReader.read(this.buffer, this.offset, size);
|
|
49
|
+
this.offset += size;
|
|
50
|
+
return val;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
module.exports = BufferReader;
|
package/lib/writer.js
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* [
|
|
12
|
-
* @param {[type]}
|
|
13
|
-
* @
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* [writeBuffer description]
|
|
23
|
-
* @param {[type]} b [description]
|
|
24
|
-
*/
|
|
25
|
-
BufferWriter.prototype.writeBuffer = function(b) {
|
|
26
|
-
this.buffer = this.buffer.concat(b.buffer);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* [toBuffer description]
|
|
31
|
-
* @return {[type]} [description]
|
|
32
|
-
*/
|
|
33
|
-
BufferWriter.prototype.toBuffer = function(){
|
|
34
|
-
|
|
35
|
-
for(
|
|
36
|
-
|
|
37
|
-
arr.push(parseInt(chunk.join(''), 2));
|
|
38
|
-
}
|
|
39
|
-
return Buffer.from(arr);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
module.exports = BufferWriter;
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* [Writer description]
|
|
4
|
+
*/
|
|
5
|
+
function BufferWriter() {
|
|
6
|
+
this.buffer = [];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* [write description]
|
|
11
|
+
* @param {[type]} d [description]
|
|
12
|
+
* @param {[type]} size [description]
|
|
13
|
+
* @return {[type]} [description]
|
|
14
|
+
*/
|
|
15
|
+
BufferWriter.prototype.write = function(d, size) {
|
|
16
|
+
for (let i = 0; i < size; i++) {
|
|
17
|
+
this.buffer.push((d & Math.pow(2, size - i - 1)) ? 1 : 0);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* [writeBuffer description]
|
|
23
|
+
* @param {[type]} b [description]
|
|
24
|
+
*/
|
|
25
|
+
BufferWriter.prototype.writeBuffer = function(b) {
|
|
26
|
+
this.buffer = this.buffer.concat(b.buffer);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* [toBuffer description]
|
|
31
|
+
* @return {[type]} [description]
|
|
32
|
+
*/
|
|
33
|
+
BufferWriter.prototype.toBuffer = function() {
|
|
34
|
+
const arr = [];
|
|
35
|
+
for (let i = 0; i < this.buffer.length; i += 8) {
|
|
36
|
+
const chunk = this.buffer.slice(i, i + 8);
|
|
37
|
+
arr.push(parseInt(chunk.join(''), 2));
|
|
38
|
+
}
|
|
39
|
+
return Buffer.from(arr);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
module.exports = BufferWriter;
|
package/package.json
CHANGED
|
@@ -1,34 +1,42 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dns2",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "A DNS Server and Client Implementation in Pure JavaScript with no dependencies.",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "node test",
|
|
8
|
-
"
|
|
9
|
-
"example-server-
|
|
10
|
-
"example-server-
|
|
11
|
-
"example-
|
|
12
|
-
"example-client-
|
|
13
|
-
"example-client-
|
|
14
|
-
"example-client-
|
|
15
|
-
"example-client-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "dns2",
|
|
3
|
+
"version": "2.0.3",
|
|
4
|
+
"description": "A DNS Server and Client Implementation in Pure JavaScript with no dependencies.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "node test",
|
|
8
|
+
"lint": "eslint .",
|
|
9
|
+
"example-server-udp": "node example/server/udp.js",
|
|
10
|
+
"example-server-tcp": "node example/server/tcp.js",
|
|
11
|
+
"example-server-doh": "node example/server/doh.js",
|
|
12
|
+
"example-client-doh": "node example/client/doh.js",
|
|
13
|
+
"example-client-udp": "node example/client/udp.js",
|
|
14
|
+
"example-client-tcp": "node example/client/tcp.js",
|
|
15
|
+
"example-client-google": "node example/client/google.js",
|
|
16
|
+
"example-client-udp-subnet": "node example/client/udp-subnet.js"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"dns"
|
|
20
|
+
],
|
|
21
|
+
"author": "Liu Song <hi@lsong.org>",
|
|
22
|
+
"contributors": [
|
|
23
|
+
"Andris Reinman <andris.reinman@gmail.com>",
|
|
24
|
+
"Eviltik <eviltik@gmail.com>",
|
|
25
|
+
"Martin Heidegger <martin.heidegger@gmail.com>"
|
|
26
|
+
],
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/song940/node-dns.git"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/song940/node-dns/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/song940/node-dns#readme",
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"eslint": "^7.28.0",
|
|
38
|
+
"eslint-config-semistandard": "^15.0.1",
|
|
39
|
+
"eslint-plugin-node": "^11.1.0",
|
|
40
|
+
"eslint-plugin-promise": "^4.2.1"
|
|
41
|
+
}
|
|
42
|
+
}
|