home / experts / perl / tutorial / 6 |
|
|
MonikerThe CodeSo, let's dive right into the code. Lines 3-6 load our modules. Getopt::Std is one module I haven't mentioned yet. It's included with the standard distribution of Perl and handles command line arguments so you don't have to. A nifty little package indeed. Line 9 sets the number of seconds we'll wait to get
a response from the server we're testing. In line 10,
the email address that will be set in the From: field of the email is assigned to the
Lines 13-22 build a multi-dimensional hash that contains the service name, port, the string that's printed once a connection has been established, and the string that we expect from the remote service. Next, we move into the main body of the code. First we initialize the hash that will hold
the value of the command line switches (line 25).
Then, we call The next thing we do in lines 27-30 is check the command-line arguments to make sure values were specified for the -h (host) and -s (service). If they weren't, we remind the user of the syntax. We also validate the service they specified to make sure it's listed in our services hash. In lines 32-45 we set several lexically scoped
variables (lines 32-37),
create a new instance of the On line 51, we print the string that's defined
in our services hash (lines 13-22) if it exists.
This is necessary for services like www where the server expects some input before it give
us some output. In the case of HTTP, we send it the string
Lastly, we wait for the string specified in the services hash that relates to the particular
service we're testing (line 54).
In the case of the www service, we're looking for the string
Lines 59-82 contain the |
home / experts / perl / tutorial / 6 |
|
Produced by Jonathan
Eisenzopf and
Created: August 4, 1999
Revised: August 4, 1999
URL: http://www.webreference.com/perl/tutorial/6/