我想问一下,是否有任何可用于ping IP地址的PHP脚本,如果是这样,请告诉我们如何做到这一点......?
答案 0 :(得分:0)
$ip = "127.0.0.1";
exec("ping -n 3 $ip", $output, $status);
print_r($output);
输出将是一个数组。像这样:
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
)
答案 1 :(得分:0)
在linux上,您可以使用以下内容:
<?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");
?>