Node.js | dnsPromises.reverse() Method

The dnsPromises.reverse() method is an inbuilt application programming interface of the promises object of dns module which is used to resolve hostname for the specified IP address using reverse DNS query.

Syntax:

dnsPromises.reverse(ip_address)

Parameters: This method has one parameter as mentioned above and described below:

  • ip_address: This parameter specifies an IP address (IPv4 or IPv6) to be resolved.

Return Value: This method returns error, hostname.

Below examples illustrate the use of dnsPromises.reverse() method in Node.js:



Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the   
// dnsPromises.reverse() method
  
// Accessing promises object from dns module
const dns = require('dns');
const dnsPromises = dns.promises;
   
// Calling dnsPromises.reverse() method 
dnsPromises.reverse('31.13.66.35').then((res) => {
    console.log(res);
});

chevron_right


Output:

[ 'edge-star-mini-shv-01-iad3.facebook.com' ]

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the   
// dnsPromises.reverse() method
  
// Accessing promises object from dns module
const dns = require('dns');
const dnsPromises = dns.promises;
   
// Calling dnsPromises.reverse() method 
// asynchronously 
(async function() {
      
    // Records from reverse function
    const records = await dnsPromises.reverse(
                        '34.218.62.116');
      
    // Printing  records
    console.log("from async: ");
    console.log(records);   
})();

chevron_right


Output:

from async:
[ 'ec2-34-218-62-116.us-west-2.compute.amazonaws.com' ]

Note: The above program will compile and run by using the node index.js command.

Reference: https://nodejs.org/api/dns.html#dns_dnspromises_reverse_ip




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.