{"id":13634775,"url":"https://github.com/tjfontaine/node-dns","last_synced_at":"2025-05-15T11:04:53.647Z","repository":{"id":1649426,"uuid":"2375148","full_name":"tjfontaine/node-dns","owner":"tjfontaine","description":"Replacement dns module in pure javascript for node.js","archived":false,"fork":false,"pushed_at":"2023-02-27T17:14:18.000Z","size":502,"stargazers_count":584,"open_issues_count":51,"forks_count":153,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-04-07T10:17:52.400Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tjfontaine.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2011-09-13T00:11:00.000Z","updated_at":"2025-02-23T06:07:29.000Z","dependencies_parsed_at":"2023-07-05T15:46:28.364Z","dependency_job_id":null,"html_url":"https://github.com/tjfontaine/node-dns","commit_stats":{"total_commits":328,"total_committers":14,"mean_commits":"23.428571428571427","dds":"0.13109756097560976","last_synced_commit":"fd05fd022a232892c4082e1bdddf79a393f6405f"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjfontaine%2Fnode-dns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjfontaine%2Fnode-dns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjfontaine%2Fnode-dns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tjfontaine%2Fnode-dns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tjfontaine","download_url":"https://codeload.github.com/tjfontaine/node-dns/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248504939,"owners_count":21115231,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T00:00:33.735Z","updated_at":"2025-04-14T18:09:36.296Z","avatar_url":"https://github.com/tjfontaine.png","language":"JavaScript","readme":"[![wercker status](https://app.wercker.com/status/ed5cab9035dfb9167714f305340490c2/s/master \"wercker status\")](https://app.wercker.com/project/byKey/ed5cab9035dfb9167714f305340490c2)\n[![Build Status](https://secure.travis-ci.org/tjfontaine/node-dns.png)](http://travis-ci.org/tjfontaine/node-dns)\n\nnative-dns -- A replacement DNS stack for node.js\n=================================================\n\n# DEAD. See forks!\n\nThis project is dead.\n\nPlease see this issue: https://github.com/tjfontaine/node-dns/issues/111\n\nSome forks have been created:\n\n- Fork by @FrancisTurner: https://github.com/FrancisTurner/native-node-dns ([relevant comment \u0026 other repos](https://github.com/tjfontaine/node-dns/issues/111#issuecomment-846349223))\n- Fork by @EduardoRuizM: https://github.com/EduardoRuizM/native-dnssec-dns ([relevant comment](https://github.com/tjfontaine/node-dns/issues/111#issuecomment-1426890990))\n- **Tangerine** by @titanism: https://github.com/forwardemail/tangerine ([relevant comment](https://github.com/tjfontaine/node-dns/issues/111#issuecomment-1444460007))\n\n*Disclaimer: I, @taoeffect, have not revied the code in this fork, and am not responsible for any issues you may or may not run into. May it be a success!*\n\n# (Below follows original README)\n\nInstallation\n------------\n\n```\nnpm install native-dns\n```\n\nClient\n------\n\nnative-dns exports what should be a 1:1 mapping of the upstream node.js dns\nmodule. That is to say if it's listed in the [docs](http://nodejs.org/docs/latest/api/dns.html)\nit should behave similarly. If it doesn't please file an [issue](https://github.com/tjfontaine/node-dns/issues/new).\n\nRequest\n-------\n\nBeyond matching the upstream module, native-dns also provides a method for\ncustomizing queries.\n\n```javascript\nvar dns = require('native-dns');\nvar util = require('util');\n\nvar question = dns.Question({\n  name: 'www.google.com',\n  type: 'A',\n});\n\nvar start = Date.now();\n\nvar req = dns.Request({\n  question: question,\n  server: { address: '8.8.8.8', port: 53, type: 'udp' },\n  timeout: 1000,\n});\n\nreq.on('timeout', function () {\n  console.log('Timeout in making request');\n});\n\nreq.on('message', function (err, answer) {\n  answer.answer.forEach(function (a) {\n    console.log(a.address);\n  });\n});\n\nreq.on('end', function () {\n  var delta = (Date.now()) - start;\n  console.log('Finished processing request: ' + delta.toString() + 'ms');\n});\n\nreq.send();\n```\n\nRequest creation takes an object with the following fields\n\n * `question` -- an instance of Question (required)\n * `server` -- defines the remote end point (required)\n  - as an object it should be\n    * `address` -- a string ip address (required)\n    * `port` -- a number for the remote port (optional, default 53)\n    * `type` -- a string indicating `udp` or `tcp` (optional, default `udp`)\nYou do not need to indicate ipv4 or ipv6, the backend will handle that\n  - a string ip address\n * `timeout` -- a number in milliseconds indicating how long to wait for the\nrequest to finish. (optional, default 4000)\n * `try_edns` -- a boolean indicating whether to use an `EDNSPacket` (optional)\n * `cache` -- can be false to disable caching, or implement the cache model, or\nan instance of Cache but with a different store (optional, default\nplatform.cache)\n\nThere are only two methods\n\n * `send` -- sends the actual request to the remote endpoint\n * `cancel` -- cancels the request and ignores any responses\n\nRequest emits the following events\n\n * `message` -- This is where you get a response, passes `(err, answer)` where\nanswer is an instance of `Packet`\n * `timeout` -- Fired when the timeout is reached\n * `cancelled` -- Fired if the request is cancelled\n * `end` -- Always fired after a request finished, regardless of disposition\n\nPlatform\n--------\n\nIf you want to customize all `resolve` or `lookup`s with the replacement client\nstack you can modify the platform settings accessible in the top level `platform`\nobject.\n\nMethods:\n\n * `reload` -- Re-read system configuration files to populate name servers and\nhosts\n\nProperties:\n\n * `ready` -- Boolean whether requests are safe to transit, true after hosts\nand name servers are filled\n * `watching` -- Boolean indicating if system configuration files are watched\nfor changes, default to false (currently can only be enabled on !win32)\n * `name_servers` -- An array of servers used for resolving queries against\n  - Each entry is an object of `{ address: \u003cstring ip\u003e, port: 53 }`\n  - On win32 this is hard coded to be google dns until there's a sane way to get\nthe data\n * `search_path` -- An array of domains to try and append after a failed lookup\n * `attempts` -- The number of retries for a failed lookup/timeout (default: 5)\n * `timeout` -- The time each query is allowed to take before trying another\nserver. (in milliseconds, default: 5000 (5 seconds))\n * `edns` -- Whether to try and send edns queries first (default: false)\n * `cache` -- The system wide cache used by default for `lookup` and `resolve`,\nset this to false to disable caching\n\nEvents:\n\n * `ready` -- Emitted after hosts and name servers have been loaded\n * `unready` -- Emitted when hosts and name servers configuration is being\nreloaded.\n\nServer\n------\n\nThere is also a rudimentary server implementation\n\n```javascript\nvar dns = require('native-dns');\nvar server = dns.createServer();\n\nserver.on('request', function (request, response) {\n  //console.log(request)\n  response.answer.push(dns.A({\n    name: request.question[0].name,\n    address: '127.0.0.1',\n    ttl: 600,\n  }));\n  response.answer.push(dns.A({\n    name: request.question[0].name,\n    address: '127.0.0.2',\n    ttl: 600,\n  }));\n  response.additional.push(dns.A({\n    name: 'hostA.example.org',\n    address: '127.0.0.3',\n    ttl: 600,\n  }));\n  response.send();\n});\n\nserver.on('error', function (err, buff, req, res) {\n  console.log(err.stack);\n});\n\nserver.serve(15353);\n```\n\nServer creation\n\n * `createServer` and `createUDPServer` -- both create a `UDP` based server,\nthey accept an optional object for configuration,\n  - `{ dgram_type: 'udp4' }` is the default option, the other is `udp6`\n * `createTCPServer` -- creates a TCP based server\n\nServer methods\n\n * `serve(port, [address])` -- specify which port and optional address to listen\non\n * `close()` -- stop the server/close sockets.\n\nServer events\n\n * `listening` -- emitted when underlying socket is listening\n * `close` -- emitted when the underlying socket is closed\n * `request` -- emitted when a dns message is received, and the packet was\nsuccessfully unpacked, passes `(request, response)`\n  - Both `request` and `response` are instances of `Packet` when you're finished\ncreating the response, you merely need to call `.send()` and the packet will\nDoTheRightThing\n * `error` -- emitted when unable to properly unpack the packet, passed `(err, msg, response)`\n * `socketError` -- remap of the underlying socket for the server, passes `(err, socket)`\n\nPacket\n------\n\nProperties:\n\n * `header`\n  - `id` -- request id\n  - `qdcount` -- the number of questions (inferred from array size)\n  - `ancount` -- the number of questions (inferred from array size)\n  - `nscount` -- the number of questions (inferred from array size)\n  - `arcount` -- the number of questions (inferred from array size)\n  - `qr` -- is a query response\n  - `opcode`\n  - `aa` -- Authoritative Answer\n  - `tc` -- Truncation bit\n  - `rd` -- Recursion Desired\n  - `ra` -- Recursion Available\n  - `res1` -- Reserved field\n  - `res2` -- Reserved field\n  - `res3` -- Reserved field\n  - `rcode` -- Response Code (see `consts.NAME_TO_RCODE`)\n * `question` -- array of `Question`s\n * `answer` -- array of `ResourceRecord`s\n * `authority` -- array of `ResourceRecord`s\n * `additional` -- array of `ResourceRecord`s\n\nMethods:\n\n * `send()` -- Handles sending the packet to the right end point\n\nQuestion\n--------\n\nA `Question` is instantiated by passing an object like:\n\n * `name` -- i.e. 'www.google.com' (required)\n * `type` -- Either the string representation of the record type, or the integer\nvalue, see `consts.NAME_TO_QTYPE` (default: 'A')\n * `class` -- The class of service, default to 1 meaning internet\n\nResourceRecord\n--------------\n\nResourceRecords are what populate `answer`, `authority`, and `additional`.\nThis is a generic type, and each derived type inherits the following properties:\n\n * `name` -- The name of the resource\n * `type` -- The numerical representation of the resource record type\n * `class` -- The numerical representation of the class of service (usually 1 for internet)\n * `ttl` -- The Time To Live for the record, in seconds\n\nAvailable Types:\n\n * `SOA`\n  - `primary` -- string\n  - `admin` -- string\n  - `serial` -- number\n  - `refresh` -- number\n  - `retry` -- number\n  - `expiration` -- number\n  - `minimum` -- number\n * `A` and `AAAA`\n  - `address` -- string\n * `MX`\n  - `priority` -- number\n  - `exchange` -- string\n * `TXT`\n  - `data` -- array of strings\n * `SRV`\n  - `priority` -- number\n  - `weight` -- number\n  - `port` -- number\n  - `target` -- string\n * `NS`\n  - `data` -- string\n * `CNAME`\n  - `data` -- string\n * `PTR`\n  - `data` -- string\n * `NAPTR`\n  - `order` -- number\n  - `preference` -- number\n  - `flags` -- string\n  - `service` -- string\n  - `regexp` -- string\n  - `replacement` -- string\n","funding_links":[],"categories":["net protocol (网络库)"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftjfontaine%2Fnode-dns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftjfontaine%2Fnode-dns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftjfontaine%2Fnode-dns/lists"}