Make low-level DNS requests with retry and timeout support.
npm install dns-socket
const dnsSocket = require('dns-socket')
const socket = dnsSocket()
socket.query({
questions: [{
type: 'A',
name: 'google.com'
}]
}, 53, '8.8.8.8', (err, res) => {
console.log(err, res) // prints the A record for google.com
})Create a new DNS socket instance. The options object includes:
retriesNumber: Number of total query attempts made duringtimeout. Default: 5.socketObject: A custom dgram socket. Default: A'udp4'socket.timeoutNumber: Total timeout in milliseconds after which a'timeout'event is emitted. Default: 7500.maxQueriesNumber: Each request has an id, this is stored as static sized array. maxQueries is the size of this array, limiting the max number of inflight requests. Default: 10000.maxRedirectsNumber: If you query for a singleArecord and get backCNAME, the lib will try to follow the chain and resolve theCNAMEto A. The maximum number of steps is defined by themaxRedirects. Default: 0timeoutChecksNumber: Timeouts are checked eachtimeoutChecksms, for large number of parallel request, you might want to increase this number. Default:timeout/ 10
Emitted when a dns query is received. The query is a dns-packet
Emitted when a dns response is received. The response is a dns-packet
Send a dns query. If host is omitted it defaults to 127.0.0.1. When the remote replies the callback is called with (err, response, query) and an response is emitted as well. If the query times out the callback is called with an error.
The host parameter can be an array, during resolve the lib will randomly select one host.
Returns the query id
Send a response to a query.
Cancel a query
Bind the underlying udp socket to a specific port. Takes the same arguments as socket#bind.
Destroy the socket.
Number of inflight queries.
MIT