make ping with PHP

Discussion in 'PHP' started by guif, Oct 8, 2008.

  1. guif

    guif New Member

    Joined:
    Jul 25, 2008
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    I would like to make a simple monitoring. I make this:

    Code:
    <?php
    $ip = $_SERVER['127.0.0.1'];
    exec("ping -n 4 $ip 2>&1", $output, $retval);
    if ($retval != 0) { 
    echo "no!"; 
    } 
    else 
    { 
    echo "yes!"; }
    ?>
    I use my internal IP: 127.0.0.1.
    The result is: NO!

    why???
     
  2. guif

    guif New Member

    Joined:
    Jul 25, 2008
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    I change this code and I put this:

    Code:
    IP: 10.110.206.123 (
    <?php
    $ping_ex = exec("ping -n 1 10.140.206.123", $ping_result, $pr);
    if (count($ping_result) > 1){
    echo "<img src=\"on.png\">";
    } else{
    echo "<img src=\"off.png\">";
    }
    ?> )
    
    
    IP: 127.0.0.1 (
    <?php
    $ping_ex = exec("ping -n 1 127.0.0.1", $ping_result, $pr);
    if (count($ping_result) > 1){
    echo "<img src=\"on.png\">";
    } else{
    echo "<img src=\"off.png\">";
    }
    ?> )
    In the first case the resulst are NO and the second case are YES.
    But... the result is YES in two cases. Why???
     
    Last edited: Oct 8, 2008
  3. guif

    guif New Member

    Joined:
    Jul 25, 2008
    Messages:
    30
    Likes Received:
    0
    Trophy Points:
    0
    yeah!
    finally I put this code:

    Code:
    <?php
    $str = exec("ping -n 1 -w 1 100.100.100.100", $input, $result);
    if ($result == 0){
    echo "<img src=\"on.png\">";
    }else{
    echo "<img src=\"off.png\">";
    }
    ?>
    It's run correctly, but i would like to insert this code into a javascript function because I insert many times this PHP and the page is very hard to load.
    I would like to insert a button:

    Code:
    <input type="submit" onClick="para();">
    and when I press this button, the javascript runs.
    Is it possible??
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Moved to PHP forum for better response.
     
  5. The Alchemist

    The Alchemist New Member

    Joined:
    Jul 7, 2012
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    So, can this code be used for performing DOS attacks on sites??
     
  6. Nishant24

    Nishant24 New Member

    Joined:
    Apr 17, 2013
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Student
    What is theuse of this code?
    And how to run this script?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice