I've seen the advice n times (where n > 3) to use the LWP libs instead of Net::Telnet. The problem is, http://mydomain.com does not specify which http daemon actually serves the page. It looks like IO::Socket::INET is the next best bet, this module lets one specify hostnames. Anyway, here's a working version of the originally posted code:
#!/usr/bin/perl
use strict;
use Time::HiRes qw( time tv_interval );
use Net::Telnet ();
$0 = 'ruffbench';
unless (@ARGV){
die "Usage: $0 <host> [<host2> <host3> ...]\n";
}
my $port = '80';
my $t = new Net::Telnet;
my $get = "GET / HTTP/1.0\n\n";
my %time;
foreach my $host (@ARGV) {
print "$0: Connecting to $host. Starting timer.\n";
my $start = [ time() ];
$t->open(Host=>$host, Port=>$port);
print "$0: Connected to $host. Sending request...\n";
$t->print($get);
print $t->waitfor(String=>"Content-Type", Timeout=>5 );
my $end = [ time() ];
$t->close;
print "\n$0: Connection closed. Timer stopped.\n\n";
$time{$host} = tv_interval($start, $end);
}
print "$0: Summary of results:\n";
foreach my $host (@ARGV) {
printf "%9s: %10s ... %2.2f seconds\n", $0, $host, $time{$host};
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.