1

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.

kailash19
  • 1,771
  • 3
  • 22
  • 39
  • You can also have a look at `Net::DRI` (I am its author). Note that whatever library you use, your requirement of "from any domain" will be hard to reach as almost each whois server has a different output so this needs a lot of effort in libraries to cater for all cases. – Patrick Mevzek Jan 03 '18 at 23:16

2 Answers2

4

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.

Oleg V. Volkov
  • 21,719
  • 4
  • 44
  • 68
4

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";
}
Borodin
  • 126,100
  • 9
  • 70
  • 144
  • But the new whois command line version do give information about google. – kailash19 Aug 21 '12 at 05:27
  • By definitions, `whois` output is public. Some registries restrict the content of it, like removing personal identification data, but at least for gTLDs you get absolutely everything right now (barring privacy proxy services of course). You may however hit the specific case of a thin registry so you need two whois requests to get all data (still currently for .COM/.NET but it will change in 2018/2019). – Patrick Mevzek Jan 03 '18 at 23:15