I am providing way too much information here in the hopes that someone may see what I'm attempting to do and offer a solution that will address the entire problem as opposed to the specific "domain name" problem that I'm addressing.

Here's the basic scenario: we have a Web site that allows dealers to sign up with manufacturers and have an entire e-commerce site created with just the upload of a spreadsheet that the dealer fills out. However, the dealer still needs a domain. After the domain is entered, the manufacturer is supposed to be able to enter the URL into one of our Web pages and the following should occur:

  1. The Technical contact should appear on the page.
  2. If not technical contact, default to the administrative contact.
  3. Default: dump all information to the page.
So far, everything works perfectly, unless the dealer has a TLD registered in a foreign country. Net::Whois is terribly out of date and will not return information for maserith.com. btrott recommended Net::ParseWhois and that's what I'm using, but it will not return information for lexicon.co.uk. It was also recommended that I try Net::XWhois, but that also fails to retrieve information for lexicon.co.uk.

The only thing which has been successful for foreign top level domains has been to use Net::Whois::Raw. This information is dumped to me in a raw format which is ugly, but I can still send to the page. You can use the following to test the usage:

perl -MNet::Whois::Raw -e "print whois(\"lexicon.co.uk\")"
The problem, however, is that all versions of whois expect that domain name without the host. The following snippet generally gets this info:
#!C:\perl\bin\perl.exe -w use strict; use Socket; my $arg = shift @ARGV or die "Need a domain, dummy!\n"; my ( $domain ) = ( $arg =~ m!^(?:[^/]+/?/)?([^/]+)! ); print "Domain is " . get_domain( $domain ); sub get_domain { my @segment = reverse split /\./, shift; my $domain; return 0 if $segment[0] =~ /^(?:local|public)$/; SEARCH_FOR_DOMAIN: { foreach ( @segment ) { ( $domain = $_, next ) if not $domain; $domain = $_ . ".$domain"; last SEARCH_FOR_DOMAIN if inet_aton( $domain ); } return 0; } return $domain; }
If it's named domain.pl, I can use the following:
domain.pl http://www.perlmonks.org/ domain.pl http://perlmonks.org/ domain.pl www.perlmonks.org etc.
Any of the above will print "Domain is perlmonks.org". Unfortunately, it will print "Domain is www.lexicon.co.uk" if I enter www.lexicon.co.uk. In this case, the domain is actually lexicon.co.uk. Why is this a problem? Because the aforementioned whois queries will fail if I supply a host/domain. How do I get just the domain if someone supplies me with a fully qualified domain name (FQDN)? I've tried Net::DNS but it is dog-slow and fails on my system. mdillon provided an interesting example of how to do this, but $q is undefined after the following line:
my $q = $res->send($domain, "SOA");
Even if I could find out why it's doing that, Net::DNS is too slow for my needs. Anyone have any ideas on how to get that TLD quickly? We're trying to automate as much as possible, so having to figure this out by hand is the last option.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to Extracting domain names from FQDNs by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.