NAME

Net::XWhois - Whois Client Interface for Perl5.

SYNOPSIS

use Net::XWhois;
   
$whois = new Net::XWhois Domain => "vipul.net" ; 
$whois = new Net::XWhois Domain => "bit.ch",
                         Server => "domreg.nic.ch", 
                         Retain => 1, 
                         Parser => { 
                            nameservers => 'nserver:\s+(\S+)', 
                         }; 

DESCRIPTION

The Net::XWhois class provides a generic client framework for doing Whois queries and parsing server response.

The class maintains an array of whois servers and associated lists of top level domains they serve for transparently selecting servers appropriate for different queries. The server details are, therefore, hidden from the user and "vipul.net" (from InterNIC), gov.ru (from RIPE) and "bit.ch" (from domreg.nic.ch) are queried in the same manner. This behaviour can be overridden by specifying different bindings at object construction or by registering associations with the class. See "register_associations()" and "new()".

One of the more important features of this module is to enable the design of consistent and predictable interfaces to incompatible whois response formats. The Whois RFC (954) does not define a template for presenting server data; consequently there is a large variation in layout styles as well as content served across servers.

To overcome this, Net::XWhois maintains another set of tables, parsing rulesets, for a few, popular response formats. (See "%PARSERS"). These parsing tables contain section names (labels) together with regular expressions that match the corresponding section text. The section text is accessed "via" labels which are available as data instance methods at runtime. By following a consistent nomenclature for labels, semantically related information encoded in different formats can be accessed with the same methods.

CONSTRUCTOR

new ()

Creates a Net::XWhois object. Takes an optional argument, a hash, that specifies the domain name to be queried. Calls lookup() if a name is provided. The argument hash can also specify a whois server, a parsing rule-set or a parsing rule-set format. (See "personality()"). Omitting the argument will create an "empty" object that can be used for accessing class data.

personality ()

Alters an object's personality. Takes a hash with following arguments:

Domain

Domain name to be queried.

Server

Server to query.

Parser

Parsing Rule-set. See "%PARSERS".

Parser => { 
  name            => 'domain:\s+(\S+)\n', 
  nameservers     => 'nserver:\s+(\S+)', 
  contact_emails  => 'e-mail:\s+(\S+\@\S+)', 
}; 
Format

A pre-defined parser format like INTERNIC, INTERNIC_FORMAT, RIPE, RIPE_CH, JAPAN etc.

Format => 'INTERNIC_CONTACT', 
Nocache

Force XWhois to ignore the cached records.

CLASS DATA & ACCESS METHODS

%PARSERS

An associative array that contains parsing rule-sets for various response formats. Keys of this array are format names and values are hash refs that contain section labels and corresponding regex masks. Parsers can be added and extended with the register_parser() method. Also see "Data Instance Methods".

my %PARSERS  = ( 
 INTERNIC => {    
  name            => 'omain Name:\s+(\S+)', 
  nameservers     => 'order:[\s\n]+(.*?)\n\s+(.*?)\n\n', 
  registrant      => 'Registrant:\s*\n(.*?)\n\n',  
  contact_admin   => 've Contact.*?\n(.*?)(?=\s*\n[^\...
  contact_tech    => 'Technical Contact.*?\n(.*?)(?=\...
  contact_zone    => 'Zone Contact.*?\n(.*?)(?=\s*\n[...
  contact_billing => 'Billing Contact.*?\n(.*?)(?=\s*...
  contact_emails  => '(\S+\@\S+)', 
 },  

See XWhois.pm for the complete definition of %PARSERS.

%ASSOC

%ASSOC is a table that associates server names with response formats and the top-level domains they serve. You'd need to modity this table if you wish to extend the module's functionality to handle a new set of domain names. Or alter existing information. register_association() provides an interface to this array. See XWhois.pm for the complete definition.

%ASSOC = (
 'whois.internic.net' => 
       [ INTERNIC,  [ qw/com net org/ ] ],
 'whois.nic.net.sg'   => 
       [ RIPE,      [ qw/sg/ ] ],
 'whois.aunic.net'    => 
       [ RIPE,      [ qw/au/ ] ]
register_parser()

Extend, modify and override entries in %PARSERS. Accepts a hash with three keys - Name, Retain and Parser. If the format definition for the specified format exists and the Retain key holds a true value, the keys from the specified Parser are added to the existing definition. A new definition is created when Retain is false/not specified.

my $w = new Net::Whois;
$w->register_parser ( 
   Name   => "INTERNIC", 
   Retain => 1, 
   Parser => { 
       creation_time => 'created on (\S*?)\.\n', 
   }; 
register_association()

Override and add entries to %ASSOC. Accepts a hash that contains representation specs for a whois server. The keys of this hash are server machine names and values are list-refs to the associated response formats and the top-level domains handled by the servers. See Net/XWhois.pm for more details.

my $w = new Net::XWhois; 
$w->register_association ( 
    'whois.aunic.net' => [ RIPE, [ qw/au/ ] ]
);
register_cache()

By default, Net::XWhois caches all whois responses and commits them, as separate files, to /tmp/whois. register_cache () gets and sets the cache directory. Setting to "undef" will disable caching.

$w->register_cache ( "/some/place/else" ); 
$w->register_cache ( undef ); 

OBJECT METHODS

Data Instance Methods

Access to the whois response data is provided via AUTOLOADED methods specified in the Parser. The methods return scalar or list data depending on the context.

Internic Parser provides the following methods:

name()

Domain name.

status()

Domain Status when provided. When the domain is on hold, this method will return "On Hold" string.

nameservers()

Nameservers along with their IPs.

registrant

Registrant's name and address.

contact_admin()

Administrative Contact.

contact_tech()

Technical Contact.

contact_zone()

Zone Contact.

contact_billing()

Billing Contact.

contact_emails()

List of email addresses of contacts.

contact_handles()

List of contact handles in the response. Contact and Domain handles are valid query data that can be used instead of contact and domain names.

domain_handles()

List of domain handles in the response. Can be used for sorting out reponses that contain multiple domain names.

lookup()

Does a whois lookup on the specified domain. Takes the same arguments as new().

my $w = new Net::XWhois;
$w->lookup ( Domain => "perl.com" ); 
print $w->response (); 

EXAMPLES

Look at example programs that come with this package. "whois" is a replacement for the standard RIPE/InterNIC whois client. "creation" overrides the Parser value at object init and gets the Creation Time of an InterNIC domain. "creation2" does the same thing but by extending the Class Parser instead. "contacts" queries and prints information about domain's Tech/Billing/Admin contacts.

AUTHOR

Vipul Ved Prakash <mail@vipul.net>

COPYRIGHT

Copyright (c) 1998 Vipul Ved Prakash. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.