in reply to Ping via CGI (was: Can't get my script working. Please help! :))

There are things in the flow of your script that appear to be remnants of several attempts to approach your task in slightly different ways. For example, $host is used early on before it is given a value. Toward the bottom, $stop_time is used without being given a value.

You need some feedback from your script to help you sort things out. If you have telnet access to the server, run the script from the command line. The results may be instructive.

If you do not have telnet access, you need to get the server to cough up messages to your web browser. Try:

use CGI qw(:standard); # you already have this use CGI::Carp; use CGI::Carp qw(fatalsToBrowser); local $SIG{__WARN__} = \&Carp::cluck;
Later, when things are better, you will likely want to remove these lines or comment them out.

Also, use strict and include -w in your hash-bang line. They do wonders for helping you see where you may have slipped up.

Having said all this, I have gone to the docs as you clearly have done, and done some (frustrated) playing around. Turns out that the protocol really does make a difference. 'udp' dies ungracefully in different ways on two different OS's. 'tcp' reports nobody home. 'icmp' reports the servers are responding. Here's a script I ran from the command prompt on a Linux machine.

use Net::Ping; my @protocols = qw(icmp tcp); my @host_array = ("www.google.com", "irc.webchat.org", "64.177.244.76"); foreach my $proto (@protocols) { my $p = Net::Ping->new($proto); foreach my $host (@host_array) { print "With $proto, $host does "; print "NOT " unless $p->ping($host); print "respond\n"; } $p->close(); }
Result:
With icmp, www.google.com does respond With icmp, irc.webchat.org does respond With icmp, 64.177.244.76 does respond With tcp, www.google.com does NOT respond With tcp, irc.webchat.org does NOT respond With tcp, 64.177.244.76 does NOT respond
Now here's the gotcha. I did this from the command prompt because you need root privilege to use the icmp protocol on a Linux machine. No good if you want to run this from a web page. And the tcp protocol option crashes on my Win98 machine.

Yuck! No easy answers but I hope this helps you sort things out.