-1

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 ?

Community
  • 1
  • 1
ks_1010
  • 15
  • 1
  • 6
  • Is your question simply "How does one get the TLD of `ir1.fp.vip.gq1.yahoo.com`, namely `yahoo.com`?" – ikegami Feb 04 '13 at 23:15
  • @ikegami yes need to fetch the TLD. – ks_1010 Feb 04 '13 at 23:24
  • Regarding your deleted question, ::PortState merely checks if it can create the socket. For a connectionless protocol like UPD, that's a useless check because the remote machine is never contacted. – ikegami Feb 27 '13 at 04:49

1 Answers1

0

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);
ikegami
  • 367,544
  • 15
  • 269
  • 518
  • In this case, the 'root' can resolve to the original IP address, but that's not always going to be the case. – ikegami Feb 04 '13 at 23:30
  • yep i used a if block to handle that have a list of 500 odd IPs, did fail for a couple of them. – ks_1010 Feb 04 '13 at 23:40