Actually, it's simple.
<?php /** * @param $ip target ip * @param $times Ping times */ function ping ($ip, $times =4) { $info = array (); if (!is_numeric ($times) | | $times -4<0) { $times = 4; } if (path_separator== ': ' | | directory_separator== '/')//linux { exec ("ping $ip -c $times", $info); if (Count ($info) < 9) { $info [' Error ']= ' timeout '; } } Else //windows { exec ("ping $ip -n $ Times ", $info); if (count ($info) < 10) { $info [' Error ']= ' timeout '; } } return $info; } $ip = ' 127.0.0.1 ';//ip address print_r (ping ($IP));? >
The results are as follows:
Array ( [0] => [1] => is ping 127.0.0.1 data with 32 bytes: [2] => from 127.0.0.1 The reply: bytes =32 time <1ms TTL=64 [3] => from 127.0.0.1 The reply: bytes =32 time <1ms TTL=64 [4] => from 127.0.0.1 The reply: bytes =32 time <1ms TTL=64 [5] => from 127.0.0.1 The reply: bytes =32 time <1ms TTL=64 [6] => [7] => 127.0.0.1 Ping Statistical Information: [8] => Packet: sent = 4, received = 4, lost = 0 (0% lost), [9] => estimated time in milliseconds for round trip: [10] => Shortest = 0ms, longest = 0ms, average = 0ms)
Try doing it!
PHP Ping ip with ping command