Namespace node.dns
Use require('dns')
to access this module.
Here is an example which resolves 'www.google.com'
then reverse
resolves the IP addresses which are returned.
var dns = require('dns'); dns.resolve4('www.google.com', function (err, addresses) { if (err) throw err; console.log('addresses: ' + JSON.stringify(addresses)); addresses.forEach(function (a) { dns.reverse(a, function (err, domains) { if (err) { console.log('reverse for ' + a + ' failed: ' + err.message); } else { console.log('reverse for ' + a + ': ' + JSON.stringify(domains)); } }); }); });
- Defined in: node.dns.js
Field Attributes | Field Name and Description |
---|---|
static |
node.dns.BADNAME
|
static |
node.dns.BADRESP
|
static |
node.dns.CONNREFUSED
|
static |
node.dns.DESTRUCTION
|
static |
node.dns.EREFUSED
|
static |
node.dns.FORMERR
|
static |
node.dns.NODATA
|
static |
node.dns.NOMEM
|
static |
node.dns.NOTFOUND
|
static |
node.dns.NOTIMP
|
static |
node.dns.SERVFAIL
|
static |
node.dns.TIMEOUT
|
Method Summary
Method Attributes | Method Name and Description |
---|---|
static |
node.dns.getHostByAddr(address, family, callback)
|
static |
node.dns.getHostByName(domain, family, callback)
|
static |
node.dns.lookup(domain, family, callback)
Resolves a domain (e.g.
|
static |
node.dns.resolve(domain, type_, callback_)
Resolves a domain (e.g.
|
static |
node.dns.resolve4(domain, callback)
The same as
dns.resolve() , but only for IPv4 queries (A records). |
static |
node.dns.resolve6(domain, callback)
The same as
dns.resolve4() except for IPv6 queries (an AAAA query). |
static |
node.dns.resolveCname(domain, callback)
|
static |
node.dns.resolveMx(domain, callback)
The same as
dns.resolve() , but only for mail exchange queries (MX records). |
static |
node.dns.resolveNs(domain, callback)
|
static |
node.dns.resolveSrv(domain, callback)
The same as
dns.resolve() , but only for service records (SRV records). |
static |
node.dns.resolveTxt(domain, callback)
The same as
dns.resolve() , but only for text queries (TXT records). |
static |
node.dns.reverse(domain, callback)
Reverse resolves an ip address to an array of domain names.
|
Field Detail
static
node.dns.BADNAME
static
node.dns.BADRESP
static
node.dns.CONNREFUSED
static
node.dns.DESTRUCTION
static
node.dns.EREFUSED
static
node.dns.FORMERR
static
node.dns.NODATA
static
node.dns.NOMEM
static
node.dns.NOTFOUND
static
node.dns.NOTIMP
static
node.dns.SERVFAIL
static
node.dns.TIMEOUT
Method Detail
-
static node.dns.getHostByAddr(address, family, callback)
- Parameters:
- {string} address
- {string} family
- {function(Error?|...[*]):undefined=} callback
-
static node.dns.getHostByName(domain, family, callback)
- Parameters:
- {string} domain
- {string} family
- {function(Error?|...[*]):undefined=} callback
-
static node.dns.lookup(domain, family, callback)Resolves a domain (e.g.
'google.com'
) into the first found A (IPv4) or AAAA (IPv6) record. The callback has arguments(err, address, family)
. Theaddress
argument is a string representation of a IP v4 or v6 address. Thefamily
argument is either the integer 4 or 6 and denotes the family ofaddress
(not necessarily the value initially passed tolookup
).- Parameters:
- {string} domain
- {string} family
- {function(Error?|...[*]):undefined=} callback
-
static node.dns.resolve(domain, type_, callback_)Resolves a domain (e.g.
'google.com'
) into an array of the record types specified by rrtype. Valid rrtypes areA
(IPV4 addresses),AAAA
(IPV6 addresses),MX
(mail exchange records),TXT
(text records),SRV
(SRV records), andPTR
(used for reverse IP lookups). The callback has arguments(err, addresses)
. The type of each item inaddresses
is determined by the record type, and described in the documentation for the corresponding lookup methods below. On error,err
would be an instanceofError
object, whereerr.errno
is one of the error codes listed below anderr.message
is a string describing the error in English.- Parameters:
- {string} domain
- {string} type_
- {string} callback_
-
static node.dns.resolve4(domain, callback)The same as
dns.resolve()
, but only for IPv4 queries (A
records).addresses
is an array of IPv4 addresses (e.g.['74.125.79.104', '74.125.79.105', '74.125.79.106']
).- Parameters:
- {string} domain
- {function(Error?|...[*]):undefined=} callback
-
static node.dns.resolve6(domain, callback)The same as
dns.resolve4()
except for IPv6 queries (anAAAA
query).- Parameters:
- {string} domain
- {function(Error?|...[*]):undefined=} callback
-
static node.dns.resolveCname(domain, callback)
- Parameters:
- {string} domain
- {function(Error?|...[*]):undefined=} callback
-
static node.dns.resolveMx(domain, callback)The same as
dns.resolve()
, but only for mail exchange queries (MX
records).addresses
is an array of MX records, each with a priority and an exchange attribute (e.g.[{'priority': 10, 'exchange': 'mx.example.com'},...]
).- Parameters:
- {string} domain
- {function(Error?|...[*]):undefined=} callback
-
static node.dns.resolveNs(domain, callback)
- Parameters:
- {string} domain
- {function(Error?|...[*]):undefined=} callback
-
static node.dns.resolveSrv(domain, callback)The same as
dns.resolve()
, but only for service records (SRV
records).addresses
is an array of the SRV records available fordomain
. Properties of SRV records are priority, weight, port, and name (e.g.,[{'priority': 10, {'weight': 5, 'port': 21223, 'name': 'service.example.com'}, ...]
).- Parameters:
- {string} domain
- {function(Error?|...[*]):undefined=} callback
-
static node.dns.resolveTxt(domain, callback)The same as
dns.resolve()
, but only for text queries (TXT
records).addresses
is an array of the text records available fordomain
(e.g.,['v=spf1 ip4:0.0.0.0 ~all']
).- Parameters:
- {string} domain
- {function(Error?|...[*]):undefined=} callback
-
static node.dns.reverse(domain, callback)Reverse resolves an ip address to an array of domain names. The callback has arguments
(err, domains)
. If there an an error,err
will be non-null and an instanceof the Error object. Each DNS query can return an error code. -dns.TEMPFAIL
: timeout, SERVFAIL or similar. -dns.PROTOCOL
: got garbled reply. -dns.NXDOMAIN
: domain does not exists. -dns.NODATA
: domain exists but no data of reqd type. -dns.NOMEM
: out of memory while processing. -dns.BADQUERY
: the query is malformed.- Parameters:
- {string} domain
- {function(Error?|...[*]):undefined=} callback