WHOIS directory lookup in PHP

Net_Whois lets you query a internet name directory service in a easy to use manner. WHOIS is a protocol which is widely used to determine the owner of a domain name, an IP address by querying an official name database. One possible application I can think of is to see if DNS servers are set correctly for various domains I handle regularly.

Installation

Net_Whois being a Pear package we will use the Pear installer as below. I recommend to always use the Pear installer to download packages rather than downloading it manually as the Pear installer automatically downloads any dependent packages.

pear install Net_Whois-1.0.2

Usage

The current library uses the following servers to execute the query:
whois.crsnic.net
whois.networksolutions.com
whois.nic.mil
whois.nic.gov
whois.arin.net
whois.ripe.net
whois.apnic.net
whois.ripn.net
whois.ra.net
.whois-servers.net
whois.6bone.net
whois.registro.br

A example code is shown below.

<?php
 
    require_once "Net/Whois.php";
 
    $whois = new Net_Whois();
    /* You can add other NIC server as a second parameter. */
    $info = $whois->query('example.com');
    echo($info);
 
?>

Note that the class returns a string, so you would need to use regular expressions to get to the relevant information.

3 thoughts on “WHOIS directory lookup in PHP

Comments are closed.