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:
Later, when things are better, you will likely want to remove these lines or comment them out.use CGI qw(:standard); # you already have this use CGI::Carp; use CGI::Carp qw(fatalsToBrowser); local $SIG{__WARN__} = \&Carp::cluck;
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.
Result: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(); }
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.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
Yuck! No easy answers but I hope this helps you sort things out.
In reply to Re: Can't get my script working. Please help! :)
by dvergin
in thread Ping via CGI (was: Can't get my script working. Please help! :))
by Llyd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |