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:
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:
The problem, however, is that all versions of whois expect that domain name without the host. The following snippet generally gets this info:perl -MNet::Whois::Raw -e "print whois(\"lexicon.co.uk\")"
If it's named domain.pl, I can use the following:#!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; }
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:domain.pl http://www.perlmonks.org/ domain.pl http://perlmonks.org/ domain.pl www.perlmonks.org etc.
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.my $q = $res->send($domain, "SOA");
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |