Retrieving raw WHOIS informations in PHP

    This post is part of the ”WHOIS in PHP: consuming the Robowhois API” series; here is a list of all the articles contained this series:

  1. A PHP library to retrieve WHOIS informations
  2. Retrieving raw WHOIS informations in PHP
  3. Checking a domain’s availability with PHP
  4. Y U NO access WHOIS informations in PHP?

After something more than a week I’m back here with a first implementation of the PHP library I was talking earlier to retrieve WHOIS informations with PHP.

In the first meeting I had with David we just setup the environment (Composer, PHPUnit and so on) and today we’ve release the first tag – 0.7.0 – of Robowhois PHP client, a PHP library to consume Robowhois APIs.

Installation

The library is assembled with Composer, so you only need to follow the canonical steps in order to download the required dependencies and use it in your own codebase

Installing the Robowhois PHP client from the command line
1
2
3
4
5
git clone [email protected]:robowhois/robowhois-php-client.git

wget http://getcomposer.org/composer.phar

php composer.phar install

then you can autoload everything through the auto-generated autoloader provided by Composer:

1
2
3
<?php

require 'vendor/.composer/autoload.php';

Retrieving raw WHOIS responses

By now we have implemented the most simple API exposed, the whois:index one, which returns the raw WHOIS informations associated to a domain.

You can take a look at the example at sample/index.php or try it live:

1
php sample/index.php

bare in mind that you’ll need to sign for a free API key up at Robowhois website (as far as I remember, they provide 500 free request, but the annual fee for unlimited requests is very cheap).

You can also be a bit more creative than the example above:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php

use Robowhois\Robowhois;
use Robowhois\Exception;

require 'vendor/.composer/autoload.php';

$robowhois = new Robowhois('INSERT-YOUR-API-KEY-HERE');

try {
    // same as $robowhois->whoisIndex(...)->getContent()
    echo $robowhois->whoisIndex('robowhois.com');
} catch (Exception\Http\Request\Unauthorized $e) {
    echo "WTF did you used a pirated API key?!?!?!";
}
} catch (Exception\Http\Response\NotFound $e) {
    echo "OMG 404 happened :-|";
}
} catch (Exception\Http\Response\ServerError $e) {
    echo "Server too drunk to fulfill the request";
}
...

Next release

In the next meeting – probably next monday – we will implement the account API, used to retrieve informations about the client’s account – useful for knowing how many remaining HTTP requests you have, the whois:availability API, to check whether a domain is available or not, and the whois:record API, identical to the one we already implemented, but returning a JSON response.

Then… take a look at the issue tracker to stay updated about the state of the project: in the next 3 weeks we should be able to go out with a stable client for y’all.


Hi there! I recently wrote an ebook on web application security, currently sold on leanpub, the Amazon Kindle store and gumroad.

It contains 160+ pages of content dedicated to securing web applications and improving your security awareness when building web apps, with chapters ranging from explaining how to secure HTTP cookies with the right flags to understanding why it is important to consider joining a bug bounty program.

Feel free to skim through some of the free chapters published on this blog and, if the content seems interesting enough to you, grab a copy on leanpub, the Amazon Kindle store, gumroad or simply checkout right down below!

Buy the Web Application Security ebook for $9.99

In the mood for some more reading?

...or check the archives.