Node.js – dnsPromises.reverse() 方法
dnsPromises.reverse() 方法执行反向 DNS 搜索以将 IPv4 或 Ipv6 地址解析为主机名数组。如果没有遇到成功状态,该 Promise 将会被错误对象拒绝。
语法
dnsPromises.reverse( ip )
其中,ip 是一个参数,用于获取要解析的 IP 地址的输入。
示例 1
创建一个名为 "reverse.js" 的文件,并复制以下代码段。创建文件后,使用 "node reverse.js" 命令运行此代码,如下例所示 −
// 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);
})输出
C:\home
ode>> node reverse.js Resolved DNS is: ['static.146.74.217.95.clients.your-server.de']
示例 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);
})();输出
C:\home
ode>> node reverse.js DNS: [ 'localhost' ]
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP