项目作者: sagi

项目描述 :
DNS-over-TLS API for Node.js
高级语言: TypeScript
项目地址: git://github.com/sagi/node-dns-over-tls.git
创建时间: 2018-08-27T22:26:31Z
项目社区:https://github.com/sagi/node-dns-over-tls

开源协议:MIT License

下载


dns-over-tls

dns-over-tls is a Node.js DNS-over-TLS API. Here’s a blog post that explains how it works.

CircleCI
Coverage Status
MIT License
version

Installation

  1. $ npm install dns-over-tls

API

We import as follows:

  1. const dnstls = require('dns-over-tls')

All API usages return a Promise that resolves to a DNS response object.

dnstls.query(name)

  1. (async () => {
  2. const dnsResponse = await dnstls.query('sagi.io')
  3. })()

Sends a DNS-over-TLS request of domain name 'sagi.io' to
Cloudflare‘s
dns-over-tls server (host is '1.1.1.1' and servername is 'cloudflare-dns.com').

dnstls.query(host, servername, name)

  1. (async () => {
  2. const dnsResponse = await dnstls.query('9.9.9.9', 'dns.quad9.net', 'sagi.io')
  3. })()

Sends a DNS-over-TLS request of domain name 'sagi.io' to host '9.9.9.9' with
servername 'dns.quad9.net'.

dnstls.query({ host, servername, name, klass = ‘IN’, type = ‘A’, port = 853 })

Allows for more advanced DNS queries.

  1. (async () => {
  2. const options = {
  3. name: 'authors.bind',
  4. host: '145.100.185.15',
  5. servername: 'dnsovertls.sinodun.com',
  6. klass: 'CH',
  7. type: 'TXT'
  8. };
  9. const dnsResponse = await dnstls.query(options)
  10. })

Sends a DNS-over-TLS request of domain name 'authors.bind' to host '145.100.185.15' with
servername 'dnsovertls.sinodun.com', class 'CH' and type 'TXT'.

Example

Say we’d like to get the NS records of domain sagi.io:

  1. const options = {
  2. name: 'sagi.io',
  3. host: '1.1.1.1',
  4. servername: 'cloudflare-dns.com',
  5. type: 'NS',
  6. };
  7. const dnsResponse = await dnstls.query(options);
  8. console.log(JSON.stringify(dnsResponse, null, 2));

Code from example.

Output:

  1. {
  2. "id": 46597,
  3. "type": "response",
  4. "flags": 384,
  5. "flag_qr": true,
  6. "opcode": "QUERY",
  7. "flag_aa": false,
  8. "flag_tc": false,
  9. "flag_rd": true,
  10. "flag_ra": true,
  11. "flag_z": false,
  12. "flag_ad": false,
  13. "flag_cd": false,
  14. "rcode": "NOERROR",
  15. "questions": [
  16. {
  17. "name": "sagi.io",
  18. "type": "NS",
  19. "class": "IN"
  20. }
  21. ],
  22. "answers": [
  23. {
  24. "name": "sagi.io",
  25. "type": "NS",
  26. "ttl": 10703,
  27. "class": "IN",
  28. "flush": false,
  29. "data": "cass.ns.cloudflare.com"
  30. },
  31. {
  32. "name": "sagi.io",
  33. "type": "NS",
  34. "ttl": 10703,
  35. "class": "IN",
  36. "flush": false,
  37. "data": "dave.ns.cloudflare.com"
  38. }
  39. ],
  40. "authorities": [],
  41. "additionals": []
  42. }

License

MIT