Node.js中的DNS模块
2015-09-22 17:36
645 查看
简介
DNS模块用于解析域名。resolve4方法用于IPv4环境,resolve6方法用于IPv6环境,lookup方法在以上两种环境都可以使用,返回IP地址(address)和当前环境(IPv4或IPv6)函数
dns.lookup(hostname[, options], callback)
将一个域名(比如 ‘google.com’)解析为第一个找到的 A 记录(IPv4)或 AAAA 记录(IPv6)。地址族 family 可以是数字 4 或 6,缺省为 null 表示同时允许 IPv4 和 IPv6 地址族。回调参数为 (err, address, family)。地址 address 参数为一个代表 IPv4 或 IPv6 地址的字符串。地址族 family 参数为数字 4 或 6,地表 address 的地址族(不一定是之前传入 lookup 的值)。
var dns = require('dns') console.log(dns.lookup('localhost', function (err, addresses, family) { if (err) { console.log('no') } else { console.log('ok') console.log('addresses:', addresses); } })) //输出 GetAddrInfoReqWrap { callback: { [Function: asyncCallback] immediately: true }, family: 0, hostname: 'localhost', oncomplete: [Function: onlookup] } ok addresses: 127.0.0.1
dns.lookupService(address, port, callback)
dns.resolve(hostname[, rrtype], callback)
dns.resolve4(hostname, callback)
dns.resolve6(hostname, callback)
dns.resolveMx(hostname, callback)
dns.resolveTxt(hostname, callback)
dns.resolveSrv(hostname, callback)
dns.resolveSoa(hostname, callback)
dns.resolveNs(hostname, callback)
dns.resolveCname(hostname, callback)
dns.reverse(ip, callback)
dns.getServers()
dns.setServers(servers)
相关文章推荐
- 从零开始nodejs系列文章
- Node.js开发框架Express4.x
- Node.js中的文件系统(FS)
- NodeJS + PhantomJS 抓取页面信息以及截图
- nodejs异步代码变量解决方案
- [ 转]Node.js模块 require和 exports
- nodeJs socketJs 搭建长连接(1) 基础讲解
- node.js 安装步骤及Grunt安装实例
- 我的第一篇博客
- 如何更好的利用Node.js的性能极限
- [Leetcode] Populating Next Right Pointers in Each Node
- nodejs图片裁剪、水印(使用images)
- Count Complete Tree Nodes
- 玩node-images模块---Node.js轻量级跨平台图像编解码库
- nodejs安装autoprefixer
- nodejs安装autoprefixer
- nodejs安装Yui Compressor
- LeetCode算法第6篇:237 Delete Node in a Linked List
- node.js环境搭建记录
- Nodejs各种请求的参数响应