The dns.resolveAny() method is an inbuilt application programming interface of the dns module which is used to resolve all records (i.e. 'ANY' or '*') for the specified hostname using DNS protocol.
Syntax:
javascript Output:
javascript Output:
dns.resolveAny( hostname, callback )Parameters: This method has two parameters as mentioned above and described below:
- hostname: This parameter specifies a string which denotes the hostname to be resolved.
- callback: It specifies a function to be called after DNS resolution of the hostnames.
- error: It specifies error if generated.
- ret: It is an object that signifies the returned records for the hostname.
- A: IPv4 address
- AAAA: IPv6 address
- ANY: Any records
- CNAME: canonical name records
- MX: mail exchange records
- NAPTR: name authority pointer records
- NS: name server records
- PTR: pointer records
- SOA: start of authority records
- SRV: service records
- TXT: text records
// Node.js program to demonstrate the
// dns.resolveAny() method
// Accessing dns module
const dns = require('dns');
// Calling dns.resolveAny() method for
// hostname geeksforgeeks.org and displaying
// them in console as a callback
dns.resolveAny('geeksforgeeks.org', (err,
ret) => console.log('records: %j', ret));
records: [
{"value":"ns-1520.awsdns-62.org","type":"NS"},
{"value":"ns-1569.awsdns-04.co.uk","type":"NS"},
{"value":"ns-245.awsdns-30.com","type":"NS"},
{"value":"ns-869.awsdns-44.net","type":"NS"}
]
Example 2:
// Node.js program to demonstrate the
// dns.resolveAny() method
// Accessing dns module
const dns = require('dns');
// Calling dns.resolveAny() method for
// hostname localhost and displaying
// them in console as a callback
dns.resolveAny('localhost', (err,
ret) => console.log('records: %j', ret));
records: [
{"address":"127.0.0.1", "ttl":0, "type":"A"}
]
Note: The above program will compile and run by using the node index.js command.
Reference: https://nodejs.org/api/dns.html#dns_dns_resolveany_hostname_callback