Created
April 3, 2015 12:17
-
-
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! :-)
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 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