Skip to content

Instantly share code, notes, and snippets.

@jhs
Created May 28, 2013 10:37
Show Gist options
  • Save jhs/5661893 to your computer and use it in GitHub Desktop.
Save jhs/5661893 to your computer and use it in GitHub Desktop.
// Example MX response with dnsd
//
// To test:
// 1. Run this program
// 2. dig @localhost -p 5353 example.com mx
var dnsd = require('dnsd')
var server = dnsd.createServer(handler)
server.zone('example.com', 'ns1.example.com', 'us@example.com', 'now', '2h', '30m', '2w', '10m')
server.listen(5353, '127.0.0.1')
console.log('Listening at 127.0.0.1:5353')
function handler(req, res) {
var question = res.question && res.question[0]
if(question.type != 'MX')
return res.end()
console.log('MX lookup for domain: %s', question.name)
res.answer.push({'name':question.name, 'type':'MX', 'data':[10, '1.2.3.1']})
res.answer.push({'name':question.name, 'type':'MX', 'data':[10, '1.2.3.2']})
res.answer.push({'name':question.name, 'type':'MX', 'data':[20, '1.2.3.3']})
res.answer.push({'name':question.name, 'type':'MX', 'data':[30, '1.2.3.4']})
return res.end()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment