home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Book HomePHP CookbookSearch this book

17.12. Getting Information About a Domain Name

17.12.3. Discussion

The Net_Whois::query( ) method returns a large text string whose contents reinforce how hard it can be to parse different Whois results:

Internet Assigned Numbers Authority (EXAMPLE2-DOM)
   4676 Admiralty Way, Suite 330
   Marina del Rey, CA 90292

   Domain Name: EXAMPLE.ORG

   Administrative Contact, Technical Contact, Billing Contact:
      Internet Assigned Numbers Authority  (IANA)  iana@IANA.ORG
      4676 Admiralty Way, Suite 330
      Marina del Rey, CA 90292
      Fax- 310-823-8649

   Record last updated on 07-Jan-2002.
   Record expires on 01-Sep-2009.
   Record created on 31-Aug-1995.
   Database last updated on 6-Apr-2002 02:56:00 EST.

   Domain servers in listed order:


For instance, if you want to parse out the names and IP addresses of the domain name servers, use this:

preg_match_all('/^\s*([\S]+)\s+([\d.]+)\s*$/m', $data, $dns, 

foreach ($dns as $server) {
    print "$server[1] : $server[2]\n";

You must set $server to the correct Whois server for a domain to get information about that domain. If you don't know the server to use, query whois.internic.net:

require 'Net/Whois.php';

print Net_Whois::query('whois.internic.net','example.org');

Whois Server Version 1.3

Domain names in the .com, .net, and .org domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.

   Domain Name: EXAMPLE.ORG
   Whois Server: whois.networksolutions.com
   Referral URL: http://www.networksolutions.com
   Name Server: A.IANA-SERVERS.NET
   Name Server: B.IANA-SERVERS.NET
   Updated Date: 19-aug-2002

>>> Last update of whois database: Wed, 21 Aug 2002 04:56:56 EDT <<<

The Registry database contains ONLY .COM, .NET, .ORG, .EDU domains and

The "Whois Server:" line says that the correct server to ask for information about example.org is whois.networksolutions.com.

Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.