www.webdeveloper.com
Results 1 to 6 of 6

Thread: Getting ping result into webpage

Hybrid View

  1. #1
    Join Date
    Feb 2003
    Posts
    86

    Getting ping result into webpage

    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();
    Man the escape pods!

  2. #2
    Join Date
    Nov 2002
    Location
    NY, USA
    Posts
    731
    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.
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  3. #3
    Join Date
    Feb 2003
    Posts
    86
    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.
    Man the escape pods!

  4. #4
    Join Date
    Feb 2003
    Location
    Derby, UK
    Posts
    456
    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

  5. #5
    Join Date
    Feb 2011
    Posts
    4
    there are many website available like this Whoisxy.com to do ping test. you can try one of them

  6. #6
    Join Date
    Sep 2010
    Posts
    84
    thank you sahaya..

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles