Question

I need to find email address and name(of admin, registrar, tech if available) using perl.

I have checked that whois output have varied output formats. I tried Net::ParseWhois and also Net::WhoisNG, but i dont get the email address or name for different domains.

Like for example: whois google.com

Is there any way i can have the above details(email and name) from any domain using any perl module or how can i parse the whois output for any domain in perl.

Was it helpful?

Solution

Quick copy/paste directly from synopsis produced following:

use strict;
use warnings;
use Net::WhoisNG;
my $w=new Net::WhoisNG('google.com');
if(!$w->lookUp()){
    print "Domain not Found\n";
    exit;
}
# If lookup is successful, record is parsed and ready for use

foreach my $type (qw(admin tech registrant bill)) {
    my $contact=$w->getPerson($type);
    if ($contact) {
        print "$type\n";
        my $email = $contact->getEmail();
        if ($email and $email =~ /\S/) {
            print "$email\n";
        } else {
            my $unparsed = join(' ', @{$contact->getCredentials()});
            # Use an regexp to extract e-mail from freeform text here, you can even pick ready one somewhere here on SO
            print "$unparsed\n";
        }
        print "----\n\n";
    }
}

Result:

admin
 dns-admin@google.com +1.6506234000 Fax: +1.6506188571
----

tech
 dns-admin@google.com +1.6503300100 Fax: +1.6506181499

I'll leave exercise of extracting e-mail from freeform text to you.

OTHER TIPS

Use Net::Whois::Parser, which will either parse existing whois text for you or call Net::Whois::Raw to get the information for you.

But note that the whois information may not be made public for all registered domains: google.com is an example.

This code demonstrates the idea

use strict;
use warnings;

use Net::Whois::Parser;
$Net::Whois::Parser::GET_ALL_VALUES = 1;

my $whois = parse_whois(domain => 'my.sample.url.com');

my @keys = keys %$whois;

for my $category (qw/ admin  registrant  tech/) {
  print "$category:\n";
  printf "  $_ => $whois->{$_}\n" for grep /^${category}_/, @keys;
  print "\n";
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top