dns.lookup(domain, [family], callback)

dns.resolve(domain, [rrtype], callback)

dns.reverse(ipaddress, callback)

Code :

var dns = require('dns');

var domain = 'www.google.com';





dns.resolve(domain, function(err, adds) {

if(err) throw err;





adds.forEach(function(add) {

dns.reverse(add, function(err, domains){

if(err) {}

else {

console.log('resolve domain name for '+add+' is '+domain);

}

});

});

});





dns.lookup(domain, function(err, add) {

if(err) throw err;

dns.reverse(add, function(err, domains){

if(err) {}

else {

console.log('lookup domain name for ' +add+' is '+domain);

}

});

});

Output :

Related articles

In this post we will show you how to get information from remote servers in Nodejs using DNS module. Before going further with this post lets take a look at DNS module in Nodejs Before going into the code lets look at some of the functions of dns module.- It resolves a domain into the first found A (i.e. IPv4) or AAAA (IPv6) record. The family parameter will be either a 4 or a 6 and represents which IP family you wish to query for the address. The callback for the dns.lookup() function will provide an error, address and family parameter if they are available.- It resolves a domain into an array of the record types specified by rrtype. Record types([rrtype]) are of the following: 'A','AAAA','MX','TXT','SRV','PTR','NS' ad=nd 'CNAME'. This method can take any of these seven record types as the parameter.- It reverses resolves ip address to an array of domain names.The difference betweenandis thatoptional second parameter is a record type, i.e. the type of DNS record you want to resolve. As mentioned above there are seven record types andmethod can take any of these seven record types as the parameter, but if none are provided it defaults to the 'A' type.will give you a list of addresses whereaswill give you only one record (i.e. first found A or AAAA record).Please Like and Share the Blog, if you find it interesting and helpful.