Whois is just about the simplest Internet protocol there is. Whois is designed to be so simple that even lusers can easily work with it.

Example:

$ telnet whois.centralnic.com 43
Trying 212.18.224.3...
Connected to whois.centralnic.com.
Escape character is '^]'.
jodrell.uk.net
Domain Name: JODRELL.UK.NET

  Registrant: Blah
  .
  .
  .
Connection closed by foreign host.

(text in bold is user input)

That's pretty simple, and it's a good one to remember when you don't have a dedicated whois client handy.

These days, the most common use for a whois client is in a website or application for checking the availability of domain names. Now, whois was never designed for this, but that didn't stop thousands of developers using it to do domain lookups.

Here is some example code for creating a whois client in Perl and PHP.

Perl

#!/usr/bin/perl
use IO::Socket;
use strict;

# This function accepts a servername and query as arguments
# and returns a scalar containing the server's response:
sub whois {
	my ($server, $query) = @_;
	my $socket = IO::Socket::INET->new("$server:43")
		or die "$server:43: $@";
	print $server "$query\r\n";
	my @response = <$socket>;
	$socket->close();
	return "[$server]\n\n".join('', @response);
}

PHP:

<?php

// this works in a similar manner to the Perl function
// above:
function whois($server, $domain) {
        $server = 'whois.centralnic.net';
        $port   = 43;
        $whois  = "[$server]\n\n";
        $socket = fsockopen($server, $port, $errno, $errstr, 30);
        if (!$socket) {
                return "$errstr ($errno).\n";
        } else {
                fputs ($socket, "$domain\r\n");
                while (!feof($socket)) {
                        $whois = $whois . fgets($socket,128);
                }
                fclose ($socket);
        }
        return $whois;
}

?>

Log in or register to write something here or to contact authors.