Eric Bergman-Terrell's Blog

Node.js Programming Tip: How to Implement WHOIS
August 24, 2015

The WHOIS service provides basic information about a given website's registration information, including the following:

If you read the WHOIS data for your own website, you may be surprised to see your email address and, perhaps more concerning, your physical address. You can pay your registration provider extra to suppress this data. But in my experience, that data is never validated...

This website offers a WHOIS utility. Give it a try!

Like many things in Node.js, it's pretty easy to perform a WHOIS query. The following code is all that's necessary.

The "config" module just has the following code relevant to WHOIS:

exports.whoisConfig = {
    whoisHost: "{put your WHOIS hostname here}"

The WHOIS data may be retrieved in multiple chunks. As each chunk is retrieved, the text string is appended with the current chunk. Finally, when the entire WHOIS data has been retrieved, the specified callback is called with all of the data.

var net = require('net');
var config = require('../libs/config');

exports.getWhois = function getWhois(domain, callback) {
    var client = new net.Socket();

    client.whoisText = "";

    var port = 43;
    var host = config.whoisConfig.whoisHost;

    client.connect(port, host, function () {'WHOIS: CONNECTED TO: ' + host + ':' + port);'WHOIS: domain: ' + domain);

        // Write a message to the socket as soon as the client is connected, the server will receive it as message from the client
        client.write(domain + '\r\n');

    // Add a 'data' event handler for the client socket
    // data is what the server sent to this socket
    client.on('data', function (data) {
        client.whoisText += data.toString();'WHOIS: DATA: ' + data);

    // Add a 'close' event handler for the client socket
    client.on('close', function () {
        callback(client.whoisText);'WHOIS: Connection closed');

        client.destroy();'WHOIS: client destroyed');

    client.on('end', function() {'WHOIS: end');

Is it a hack to store the WHOIS text in the client object? Yes. But that's a very convenient place to store it. The best approach would be to create a new object for the entire WHOIS data retrieval, and store the text there.

For WHOIS source code for Ruby on Rails and .NET, check out this blog post.

WHOIS living in my grass?

WHOIS living in my grass?

Keywords: Node.js, node, JavaScript, Express, WHOIS, net.Socket, port 43, Ruby on Rails, .NET

Reader Comments

Comment on this Blog Post

Recent Posts

EBTCalc Users: A Desktop Version is Now Available!October 25, 2019
Python Script to Audit MediaMonkey TranscodingAugust 15, 2019
How to decompile Java code with JetBrains IntelliJ IDEA (2018.2.3, Windows 10)October 5, 2018
Java Programming Tip: SWT Photo Frame ProgramOctober 31, 2016
Vault 3 (Desktop) Version 1.63 ReleasedSeptember 9, 2016
"Compliance with Court Orders Act of 2016"April 9, 2016
Disable "Visual Voicemail" on Android / T-MobileJanuary 17, 2016