【发布时间】:2011-09-26 13:31:15
【问题描述】:
我想按照标题所述做。 ping 用户 IP 并以 ms 为单位返回结果,例如:
Ping IP 返回 400 毫秒。
我不知道该怎么做,但我希望它会相对简单。我可以访问 exec() 函数和与之类似的函数,因为我将在虚拟专用服务器上运行此脚本。
提前致谢。
【问题讨论】:
我想按照标题所述做。 ping 用户 IP 并以 ms 为单位返回结果,例如:
Ping IP 返回 400 毫秒。
我不知道该怎么做,但我希望它会相对简单。我可以访问 exec() 函数和与之类似的函数,因为我将在虚拟专用服务器上运行此脚本。
提前致谢。
【问题讨论】:
试试这个
<?php
$out = array();
exec('ping -c 4 '.$_SERVER['REMOTE_ADDR'], $out);
print_r($out);
?>
【讨论】:
试试这个:
<?php
$ip = $_SERVER['SERVER_ADDR']; // Get the IP address of the visitor
$result = system('ping -n 1 '.$ip, $retval); // the result contains the last line of the ping command.
if ($retval==0) echo "OK";
if ($retval==1) echo "NOT OK";
?>
【讨论】: