我想按标题说明。要ping用户IP并以ms为单位返回结果,例如:
Ping IP 返回400ms。
我不知道该怎么做但我希望它会相对简单。我可以访问exec()函数和类似的函数,因为我将在虚拟专用服务器上运行此脚本。
提前致谢。
答案 0 :(得分:1)
试试这个
<?php
$out = array();
exec('ping -c 4 '.$_SERVER['REMOTE_ADDR'], $out);
print_r($out);
?>
答案 1 :(得分:0)
试试这个:
<?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";
?>