Created
January 14, 2013 18:56
-
-
Save vikrum/4532349 to your computer and use it in GitHub Desktop.
A custom DNS server in NodeJS that saves off queries to Firebase so they can be retrieved later. Accompanying blog post: http://5f5.org/ruminations/dns-debugging-over-http.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var crypto = require('crypto'); | |
var dns = require('native-dns'); | |
var rest = require('restler'); | |
var server = dns.createServer(); | |
server.on('request', function (request, response) { | |
var domain = request.question[0].name; | |
if(domain == 'webutils.flourishworks.com') { | |
// Don't log this because it can't be uniquely identified and subsequently retrieved | |
response.answer.push(dns.CNAME( { name: domain, data: 'ghs.googlehosted.com.', ttl: 30 })); | |
response.send(); | |
} | |
else { | |
var sha256 = crypto.createHash('sha256').update(domain).digest("hex"); | |
rest.postJson('http://firedns.firebaseio.com/'+sha256+'/.json', | |
{ poweredBy: 'Firebase', | |
timestamp: new Date().getTime(), | |
header: request.header, | |
question: request.question, | |
address: request.address} | |
).on('complete', function() { | |
response.answer.push(dns.CNAME( { name: domain, data: 'ghs.googlehosted.com.', ttl: 30 })); | |
response.send(); | |
}); | |
} | |
}); | |
server.on('error', function (err, buff, req, res) { console.log(err.stack); }); | |
server.serve(53); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment