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万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章