Touching the fruit
--#--
Before you pick the apples, you need to reach
the apples. Let's start by establishing a connection to the
Network Solutions server.
The Network Solutions site presents a Web form to the user
for querying the database. If you wade through the
HTML
in the form's source, you'll find the tags you need to formulate
your robotic request.
A few lines below the <FORM> tag, you'll find an INPUT tag:
This field holds the entirety of your query. The information gleaned
here is all we need to write a user agent robot to go out
periodically and query GM's domain registrations.
Our script starts by telling the shell where to find the Perl interpreter,
followed immediately by where the interpreter can find the powerful
routines supplied by Mr. Aas and Mr. Koster:
#!/usr/bin/perl
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
Then we create the robot (user agent) that will make the request and
establish the CGI process we want it to query:
$ua = new LWP::UserAgent;
$ua->agent("DarkSpell/6.0"); # the so-called "browser string"
$process = 'http://www.networksolutions.com/cgi-bin/whois/whois';
We identify what we're asking for and how we'll present it to NSI's CGI.
$name = 'STRING';
$query = 'name General Motors';
Then we formulate the request, establishing the method, the process we're
querying, and the name/value pair of the query, which we pass as a one-row
Perl hash table. To be polite, we tell the process we'll accept HTML text.
$request = POST $process, [$name => $query];
$request->header('Accept => 'text/html');
That's about it. Well, we need to actually send the request. And we
need to catch NSI's response in a Perl variable:
$response = $ua->request($request);
That's 11 lines of Perl, and we've gotten our first apples. We need, however,
to check for error conditions, and we need to present the apples for show-and-tell.
if (!$response->is_success) {
print "Uh-oh! Came up empty\n";
}
else {
print $response->content, "\n";
}
OK, so what we've got is raw HTML, and we're just printing it to
stdout. It probably whizzed past so fast you couldn't read it. You
could redirect it to a file, but that would be only marginally
more useful. Besides, there is still more information to get from
NSI's WHOIS. Let's see how.