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:
retries
Number: Number of total query attempts made duringtimeout
. Default: 5.socket
Object: A custom dgram socket. Default: A'udp4'
socket.timeout
Number: Total timeout in milliseconds after which a'timeout'
event is emitted. Default: 7500.
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 localhost. 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.
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