Node.js_Dns模塊

/**
 * Created by cxm on 2016/1/11.
 */

var dns = require("dns");

// 將域名(比如 'runoob.com')解析爲第一條找到的記錄 A (IPV4)或 AAAA(IPV6)。參數 options可以是一個對象或整數。如果沒有提供 options,IP v4 和 v6 地址都可以。如果 options 是整數,則必須是 4 或 6。
//dns.lookup("www.baidu.com", function(err, address, family){
//    console.log("IP:" + address);
//    dns.reverse(address, function(err, hostname){
//        if (err)
//        {
//            console.log(err.stack);
//            return;
//        }
//        console.log(hostname);
//    });
//});

// 使用 getnameinfo 解析傳入的地址和端口爲域名和服務。
//dns.lookupService("14.215.177.37", 8080, function(err, hostname){
//    if (err)
//    {
//        console.log(err.stack);
//        return;
//    }
//    console.log(hostname);
//});

// 將一個域名(如 'runoob.com')解析爲一個 rrtype 指定記錄類型的數組。
//dns.resolve("runoob.com", "A", function(err, address){
//    if (err)
//    {
//        console.log(err.stack);
//        return;
//    }
//    console.log(address);
//});

// 和 dns.resolve() 類似, 僅能查詢 IPv4 (A 記錄)。 addresses IPv4 地址數組 (比如,['74.125.79.104', '74.125.79.105', '74.125.79.106'])。
//dns.resolve4("www.baidu.com", function(err, hostname){
//    if (err)
//    {
//        console.log(err.stack);
//        return;
//    }
//    console.log(hostname);
//});

// 和 dns.resolve4() 類似, 僅能查詢 IPv6( AAAA 查詢)
//dns.resolve6("www.baidu.com", function(err, hostname){
//    if (err)
//    {
//        console.log(err.stack);
//        return;
//    }
//    console.log(hostname);
//});

// 和 dns.resolve() 類似, 僅能查詢郵件交換(MX 記錄)。
//dns.resolveMx("[email protected]", function(err, hostname){
//    if (err)
//    {
//        console.log(err.stack);
//        return;
//    }
//    console.log(hostname);
//});

// 和 dns.resolve() 類似, 僅能進行別名記錄查詢 (CNAME記錄)。addresses 是對 hostname 可用的別名記錄數組 (比如,, ['bar.example.com'])。
//dns.resolveCname("bar.example.com", function(err, hostname){
//    if (err)
//    {
//        console.log(err.stack);
//        return;
//    }
//    console.log(hostname);
//});

// 反向解析 IP 地址,指向該 IP 地址的域名數組。
//dns.reverse("192.168.1.1", function(err, hostname){
//    if (err)
//    {
//        console.log(err.stack);
//        return;
//    }
//    console.log(hostname);
//});

// 返回一個用於當前解析的 IP 地址數組的字符串。
//console.log(dns.getServers());

// 指定一組 IP 地址作爲解析服務器。
console.log(dns.setServers(dns.getServers()));

發佈了260 篇原創文章 · 獲贊 7 · 訪問量 22萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章