- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Node.js – dnsPromises.reverse() Method
The dnsPromises.reverse() method performs a reverse DNS search to resolve the IPv4 or Ipv6 address to an array of hostnames. The promise is rejected with an Error object if a Success status is not encountered.
Syntax
dnsPromises.reverse( ip )
where, ip is the parameter that takes the input for the IP address to be resolved.
Example 1
Create a file with the name "reverse.js" and copy the following code snippet. After creating the file, use the command "node reverse.js" to run this code as shown in the example below −
// dns.reverse() Demo Example // Importing the dns module const dns = require('dns'); const dnsPromises = dns.promises; // Passing IP to find the DNS name dnsPromises.reverse('95.217.74.146').then((response) => { console.log("Resolved DNS is:", response); })
Output
C:\home
ode>> node reverse.js Resolved DNS is: ['static.146.74.217.95.clients.your-server.de']
Example 2
// dns.reverse() Demo Example // Importing the dns module const dns = require('dns'); const dnsPromises = dns.promises; // Setting ttl as true const options={ ttl:true, }; // Calling dnsPromises.reverse() method // asynchronously (async function() { const records = await dnsPromises.reverse('127.0.0.8', options); // Printing records console.log("DNS: ", records); })();
Output
C:\home
ode>> node reverse.js DNS: [ 'localhost' ]
Advertisements