Friday, January 8, 2010

Recipe 16.11. Getting Information About a Domain Name










Recipe 16.11. Getting Information About a Domain Name



16.11.1. Problem


You
want to look up contact information or other details about a domain name.




16.11.2. Solution


Use

PEAR's Net_Whois class:


require 'Net/Whois.php';
$server = 'whois.networksolutions.com';
$query = 'example.org';
$data = Net_Whois::query($server, $query);





16.11.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:


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

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
US
310-823-9358
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:

A.IANA-SERVERS.NET 192.0.34.43
B.IANA-SERVERS.NET 193.0.0.236



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,
PREG_SET_ORDER);

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');

require 'Net/Whois.php';

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

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
Registrar: NETWORK SOLUTIONS, INC.
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
Registrars.



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




16.11.4. See Also


PEAR's Net_Whois class at http://pear.php.net/package-info.php?package=Net_Whois.













No comments: