native-dns
想建立一套強韌的DNS系統嗎,用Node.js也可以喔!native-dns是一個實作dns協定的工具包,提供你呼叫dns server以及當做dns server的方式,透過此套件,寫一個dns server是輕而易舉的事喔!
Github repository
http://github.com/tjfontaine/node-dns
Installation
npm install native-dns
Sample Usage
/**
*
*/
var dns = require('native-dns'),
util = require('util');
var question = dns.Question({
name: 'www.google.com',
type: 'A',
});
var start = Date.now();
var req = dns.Request({
question: question,
server: { address: '8.8.8.8', port: 53, type: 'udp' },
timeout: 1000,
});
req.on('timeout', function () {
console.log('Timeout in making request');
});
req.on('message', function (err, answer) {
answer.answer.forEach(function (a) {
console.log(a.address);
});
});
req.on('end', function () {
var delta = (Date.now()) - start;
console.log('Finished processing request: ' + delta.toString() + 'ms');
});
req.send();