代码语言:javascript复制
class Ping
{
public function pings($ip, $times = 4)
{
$info = array();
if (!is_numeric($times) || $times - 4 < 0) {
$times = 4;
}
exec("ping $ip -c $times", $info);
if (count($info) < 9) {
$info['error'] = 'timeout';
}
return $info;
}
/**
* @param Json信息输出
* @arr:需要转换的数组
*/
public function json($arr = array(), $code = JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
{
header("Content-Type:text/json");
exit(json_encode($arr, $code));
}
}
$a = new Ping();
$ip = '183.220.151.32';
//var_dump($a->pings($ip));
echo $a->json($a->pings($ip));
然后写完了,感觉貌似没多大用hhh