如何在php中ping IP地址并给出结果 [英] how to ping ip addresses in php and give results

查看:348
本文介绍了如何在php中ping IP地址并给出结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
使用PHP ping IP地址并回显结果

Possible Duplicate:
Pinging an IP address using PHP and echoing the result

您如何ping php中的IP地址.并给出结果,就好像您在Windows中的cmd程序上一样

How do you ping an ip addresses in php. and give the the results as if you are on cmd program in windows

<?php

  system(‘ping -c 192.168.0.104’); // Ping IP address.<br>

   echo "pinged";<br>

?>

推荐答案

$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
)

这篇关于如何在php中ping IP地址并给出结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆