Node.js – dns.getServers() 方法
dns.getServers() 方法返回一个 IP 地址字符串数组。地址将按照 RFC 5952 标准进行格式化,该标准针对 DNS 解析而配置。如果使用了自定义端口,该字符串还将包含端口部分。
语法
dns.getServers()
参数
由于它返回服务器列表,因此无需任何参数。
示例 1
创建一个文件 "getServers.js" 并复制以下代码段。创建文件后,使用命令 "node getServers.js" 运行此代码。
// dns.getServers() Node js Example
// Importing the dns module
const dns = require('dns');
// Reading the IP related info
// for the current host
console.log(dns.getServers());输出
[ '213.133.98.98', '213.133.100.100', '213.133.99.99' ]
示例 2
// dns.getServers() Node js Example
// Importing the dns module
const dns = require('dns');
// Reading the IP related info
// for all hosts
allServers = dns.getServers();
// Iterating over all the IP's and printing them
allServers.forEach(element => {
console.log(element);
});输出
213.133.98.98 213.133.100.100 213.133.99.99
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP