Skip to content

Instantly share code, notes, and snippets.

@serverwentdown
Created April 3, 2015 12:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serverwentdown/178e42ca26992b5ee065 to your computer and use it in GitHub Desktop.
Save serverwentdown/178e42ca26992b5ee065 to your computer and use it in GitHub Desktop.
A tiny xip.io clone quickly written in node.js. Requires module dnsd. Sample site at .addr.eurica.eu.org. Report vulnaribilities if any! :-)
var dnsd = require('dnsd');
var server = dnsd.createServer(handler);
server.zone('addr.eurica.eu.org', 'eurica.eu.org', 'webmaster@eurica.eu.org', 'now', '2h', '30m', '2w', '10m');
server.listen(5354);
console.log("Server running at " + server.ip + ":" + server.port);
function handler(req, res) {
var question = res.question[0];
var hostname = question.name;
//var ttl = Math.floor(Math.random() * 3600);
var ttl = 10;
console.log(question);
console.log('%s:%s/%s %j', req.connection.remoteAddress, req.connection.remotePort, req.connection.type, req);
var hostnames = hostname.split(".");
var ip = [];
for (var i = 0; i < hostnames.length; i++) {
if (parseInt(hostnames[i], 10) == hostnames[i]) {
ip.push(parseInt(hostnames[i]));
}
}
if (ip.length >= 4) {
ip = ip[0] + "." + ip[1] + "." + ip[2] + "." + ip[3];
}
else {
ip = "127.0.0.1";
}
res.answer.push({
name: hostname,
type: 'A',
data: ip,
ttl: ttl
});
res.end();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment