Node.js - dns.resolveCname() 方法
dns.resolveCname() 方法使用 DNS 协议为主机名解析 CNAME 记录。传递给回调函数的 地址 参数将包含一个数组中的规范记录数组。
语法
dns.resolveCname(hostname, callback)
参数
hostname - 此参数获取要解析的主机名的输入。
callback - 此函数将捕获错误(如果有)。
addresses - 返回主机名的 CNAME 地址。
示例 1
创建名为 "resolveCname.js" 的文件并复制以下代码片段。创建文件后,使用命令 "node resolveCname.js" 运行此代码,如下例所示 −
// dns.resolveCname() Demo Example
// Importing the dns module
const dns = require('dns');
// Passing the argument below
dns.resolveCname('tutorialspoint.com', (err, addresses) => console.log('addresses: %j', addresses));输出
C:\home
ode>> node resolveCname.js QueryReqWrap { bindingName: 'queryCname', callback: [Function], hostname: 'tutorialspoint.com', oncomplete: [Function: onresolve], ttl: false, channel: ChannelWrap {} } addresses: undefined
示例 2
// dns.resolveCname() Demo Example
// Importing the dns module
const dns = require('dns');
// Passing the argument below
dns.resolveCname('localhost', (err, addresses) => console.log('addresses: %j', addresses));输出
C:\home
ode>> node resolveCname.js addresses: undefined
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP