Question

Possible Duplicate:
Extraction of TLD from urls and sorting domains and subdomains for each TLD file

For example: fetching yahoo.com from the PTR record 45.36.190.206.in-addr.arpa domain name pointer ir1.fp.vip.gq1.yahoo.com.

I am using Net::Nslookup; nslookup(host => "206.190.36.45", type => "PTR"); which returns ir1.fp.vip.gq1.yahoo.com.

Need to fetch just "yahoo.com" from the ptr record.

How to fetch this using perl ?

Was it helpful?

Solution

Is your question simply "How does one get the TLD of ir1.fp.vip.gq1.yahoo.com, namely yahoo.com?"

use Domain::PublicSuffix qw( );

my $dps = Domain::PublicSuffix->new();

my $host = 'ir1.fp.vip.gq1.yahoo.com';

$host =~ s/\.\z//;  # D::PS doesn't handle "domain.com.".
my $root = $dps->get_root_domain($host)
   or die $dps->error();

say $root;

By the way, you can use the builtin / system call gethostbyaddr to get the PTR record.

use Socket qw( inet_aton AF_INET );
my $host = gethostbyaddr(inet_aton("206.190.36.45"), AF_INET);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top