Click to See Complete Forum and Search --> : Getting ping result into webpage
geuis
05-15-2003, 09:01 PM
I am trying to write a simple script that will ping an IP or url and then return the result to the webpage. When I run the code below, the page times out and doesn't display in IE. When I run the script manually, it doesn't say anything then the window closes very quickly.
Can anyone tell me what I'm doing wrong here? thanks.
use Net::Ping;
$p = Net::Ping->new("icmp");
$my_addr = "www.yahoo.com";
$p->bind($my_addr); # Specify source interface of pings
foreach $host (@host_array)
{
print "<html>", "\n";
print "<body>","\n";
print "Server is ";
print "down." unless $p->ping($host, 2);
print "reachable.\n";
sleep(1);
print "</body> </html>";
}
$p->close();
jeffmott
05-18-2003, 10:03 AM
The reason for your problem is in the documentation for Net::Ping.Note that a live remote host may still fail to be pingable by one or more of these protocols. For example, www.microsoft.com is generally alive but not pingable.Also, when you say it didn't display in IE, did you make a point of saying that because you get a different result in a different browser? (which shouldn't anyway). But you should notice that your HTML output is inside a loop that (from what you have posted here) will never run.
geuis
05-18-2003, 10:51 AM
I have tried this code with no loop at all. The code I posted here is an earlier iteration of some of the attempts I've made.
If you try to ping www.yahoo.com, you will find it *does* return pings. Why else do you think that I chose to use that site? Common sites such as www.microsoft.com, www.bellsouth.com, and www.cnn.com do not return ICMP pings. Yahoo does. That is not an issue in this case.
I have updated the code I am attempting to use now. It is below. It still will successfully dectect if the remote server is up or down, but it will not post the results when accessed through a website.
use Net::Ping;
$p = Net::Ping->new("icmp");
$my_addr = "www.yahoo.com";
$p->bind($my_addr); # Specify source interface of pings
print "<html>", "\n";
print "<body>","\n";
print "Server is ";
print "down." unless $p->ping($host, 2);
print "reachable.\n";
print "</body> </html>";
}
$p->close();
It returns working results when run by itself, but not when accessed through IE. Thanks for any help.
DaiWelsh
05-21-2003, 11:43 AM
All CGI scripts require outputting headers before content e.g.
print("Content-Type: text/html\n\n");
at the top of your script, otherwise it will error.
HTH,
Dai
sahaya
08-30-2011, 04:46 AM
there are many website available like this Whoisxy.com (http://www.whoisxy.com/) to do ping test. you can try one of them
franklinn
09-14-2011, 01:32 AM
thank you sahaya..