Last active
October 21, 2022 21:48
-
-
Save debloper/6032516 to your computer and use it in GitHub Desktop.
A simple WHOIS & Reverse Lookup server written in Node.js. Run `npm install express`, then `node <file>.js` to get the server(s) up
This file contains hidden or 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 net = require("net") | |
, dns = require("dns") | |
, exp = require("express") | |
, app = exp(); | |
app.configure(function() { | |
app.use(exp.logger()); | |
app.use(app.router); | |
}); | |
app.get("/:domain", function (req, res) { | |
var domain = req.params.domain | |
, server = domain.substring( | |
domain.lastIndexOf(".") + 1 | |
) + ".whois-servers.net" | |
, port = 43; | |
dns.resolveCname(server, function(error, addresses) { | |
var host = "", data = ""; | |
if(!error) host = addresses[0]; | |
else host = server; | |
var socket = net.createConnection(port, host, function() { | |
socket.write("domain " + domain + "\r\n", "ascii"); | |
}); | |
socket.setEncoding('ascii'); | |
socket.on("data", function(response) { | |
data = data + response; | |
}).on("close", function(error) { | |
if(error) data = 'No WHOIS data for this domain!'; | |
res.header("Content-Type", "application/json"); | |
res.end(data, "utf-8"); | |
}); | |
}); | |
}); | |
app.listen(8000); | |
console.log("Now, go visit `http://127.0.0.1:8000/google.com` from your browser..."); |
This file contains hidden or 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 dns = require("dns") | |
, exp = require("express") | |
, app = exp(); | |
app.configure(function() { | |
app.use(exp.logger()); | |
app.use(app.router); | |
}); | |
app.get("/:domain", function (req, res) { | |
var domain = req.params.domain | |
, data; | |
dns.lookup(domain, null, function (error, address) { | |
console.log(address || error); | |
dns.reverse(address, function(error, domains) { | |
res.header("Content-Type", "application/json"); | |
res.end(JSON.stringify(domains, null, "\t"), "utf-8"); | |
}) | |
}); | |
}); | |
app.listen(8080); | |
console.log("Now, go visit `http://127.0.0.1:8080/google.com` from your browser..."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment