susmith has asked for the wisdom of the Perl Monks concerning the following question:

Hi Are there any utility to find the top-level domain name from the subdomian url. Can any one help me? Thanks in advcance

Replies are listed 'Best First'.
Re: find the domain name from subdomian
by aquarium (Curate) on Mar 17, 2010 at 05:25 UTC
    What exactly are you after? There's no such thing as a top-level domain name from a subdomain in DNS. DNS records merely show information for a particular domain, for which the dns server(s) are authoritative. You would need to (most likely manually) follow domain registration records to determine which entity is responsible for which domain and (possibly) subdomain(s).
    the hardest line to type correctly is: stty erase ^H
Re: find the domain name from subdomian
by ikegami (Patriarch) on Mar 17, 2010 at 14:49 UTC
    The top level domain is what's after the last "." of a domain, ignoring trailing ".". It's easy to find using a regex after extracting the host from the url. URI can be used to parse the url for you.
    use URI qw( ); my $host = URI->new('http://www.google.co.uk/')->host(); die("No domain\n") if !defined($host) || $host =~ /^[\d.]*\z/; my ($tld) = $host =~ /\.([^.]*)\.?\z/; print("$tld\n"); # uk
Re: find the domain name from subdomian
by Khen1950fx (Canon) on Mar 17, 2010 at 05:07 UTC
    Maybe this will help?
    #!/usr/bin/perl use strict; use warnings; use Sys::Hostname::FQDN qw(fqdn); my $fqdn = fqdn(); print $fqdn, "\n";
      I have list of sub-domain url in my table. I have find the domain name of each of these.
Re: find the domain name from subdomian
by Anonymous Monk on Mar 17, 2010 at 06:19 UTC
    $ perl -MURI -le"print URI->new( shift )->host " http://search.cpan.or +g/ search.cpan.org $ perl -MURI -le"print join q!.!, (split /\./, URI->new( shift )->host +)[-2,-1] " http://search.cpan.org/ cpan.org
    URI, Regexp::Common::dns