O'Reilly logo

Perl Cookbook by Nathan Torkington, Tom Christiansen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Whois to Retrieve Information from the InterNIC

Problem

You want to find out who owns a domain, as if you’d used the Unix whois command.

Solution

Use the CPAN module Net::Whois:

use Net::Whois;

$domain_obj = Net::Whois::Domain->new($domain_name)
    or die "Couldn't get information on $domain_name: $!\n";

# call methods on $domain_obj to get name, tag, address, etc.

Discussion

Whois is a service provided by domain name registration authorities to identify owners of domain names. Historically, queries were made with the whois (1) program on Unix systems, which returned about fifteen lines of information, including the names, addresses, and phone numbers of the administrative, technical, and billing contacts for the domain.

The Net::Whois module is a client for the whois service, just like whois (1). It connects to a whois server (the default is whois.internic.net, the master server for the ".com", ".org", ".net", and ".edu" domains) and gives you access to the information through method calls on an object.

To request information on a domain, create a new Net::Whois::Domain object. For instance, to look up information on perl.org:

$d = Net::Whois::Domain->new( "perl.org" )
    or die "Can't get information on perl.org\n";

The only guaranteed fields are the domain name and the tag— the domain’s unique identifier in the NIC records:

print "The domain is called ", $d->domain, "\n";
print "Its tag is ", $d->tag, "\n";

Information that may be present includes: name of the domain’s company or product ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required