-1

I want to ask is any php script available which is able to ping an IP Address if is it so let me know how we can do that ...?

Ehsan Ilahi
  • 298
  • 5
  • 15

2 Answers2

0
$ip =   "127.0.0.1";
exec("ping -n 3 $ip", $output, $status);
print_r($output);

Output will be an Array. Something like this:

Array
(
    [0] => 
    [1] => Pinging 127.0.0.1 with 32 bytes of data:
    [2] => Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
    [3] => Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
    [4] => Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
    [5] => 
    [6] => Ping statistics for 127.0.0.1:
    [7] =>     Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
    [8] => Approximate round trip times in milli-seconds:
    [9] =>     Minimum = 0ms, Maximum = 0ms, Average = 0ms
)
haMzox
  • 2,073
  • 1
  • 12
  • 25
0

On linux, you the use the following :

<?php
    function ping($ip) {
        $result = exec("/bin/ping -n 3 $ip", $outcome, $status);
        if (0 == $status) {
            $status = "alive";
        } else {
            $status = "dead";
        }
        echo $status;
    }

    ping("80.80.80.80");

?>
mrid
  • 5,782
  • 5
  • 28
  • 71