Node.js - 的 dns.resolve6() 方法
dns.resolve6() 方法使用 DNS 協議解析主機名的 IPv6 地址(AAAA 記錄)。傳遞至 回撥 的 地址引數將包含 IPv6 地址的陣列。
語法
dns.resolve6(hostname, [options], callback)
引數
hostname – 此引數接受要解析的主機名的輸入。
options – 它可以具有以下選項 −
ttl – 此選項定義每條記錄的生存時間(TTL)。
示例 1
建立一個以 "resolve6.js" 為檔名的檔案並複製以下程式碼段。在建立檔案後,使用命令 “node resolve6.js” 執行此程式碼,命令使用如下例所示:
// dns.resolve6() Demo Example
// Importing the dns module
const dns = require('dns');
// Passing a single dns to get values
dns.resolve6('tutorialspoint.com', (err, address) => console.log('address: %j', address));輸出
C:\home
ode>> node resolve6.js address: undefined
示例 2
// dns.resolve6() Demo Example
// Importing the dns module
const dns = require('dns');
// Setting the ttl option as true
const options = {
ttl: true,
};
// Passing the dns address below
dns.resolve6('google.com', options, (err, address) => console.log('address: %j', address));輸出
C:\home
ode>> node resolve6.js address: [{"address":"2404:6800:4002:81d::200e","ttl":231}]
廣告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP