bbodinat
1/21/2017 - 3:36 PM

A simple WHOIS & Reverse Lookup server written in Node.js. Run `npm install express`, then `node <file>.js` to get the server(s) up

A simple WHOIS & Reverse Lookup server written in Node.js. Run npm install express, then node <file>.js to get the server(s) up

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...");
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...");