PHP 使用 ping 命令ping ip

來源:互聯網
上載者:User

標籤:io   ar   使用   sp   資料   on   cti   bs   時間   

其實很簡單

 <?php /**  *@param $ip target ip  *@param $times ping times  */ function ping($ip,$times=4) {       $info = array();      if(!is_numeric($times) ||  $times-4<0)      {           $times = 4;      }      if (PATH_SEPARATOR==‘:‘ || DIRECTORY_SEPARATOR==‘/‘)//linux      {           exec("ping $ip -c $times",$info);           if (count($info) < 9)           {            $info[‘error‘]=‘timeout‘;        }  }  else //windows  {       exec("ping $ip -n $times",$info);       if (count($info) < 10)       {         $info[‘error‘]=‘timeout‘;       }  }  return $info; } $ip = ‘127.0.0.1‘;//IP地址 print_r(ping($ip));?>

結果如下:

Array(    [0] =>     [1] => 正在 Ping 127.0.0.1 具有 32 位元組的資料:    [2] => 來自 127.0.0.1 的回複: 位元組=32 時間<1ms TTL=64    [3] => 來自 127.0.0.1 的回複: 位元組=32 時間<1ms TTL=64    [4] => 來自 127.0.0.1 的回複: 位元組=32 時間<1ms TTL=64    [5] => 來自 127.0.0.1 的回複: 位元組=32 時間<1ms TTL=64    [6] =>     [7] => 127.0.0.1 的 Ping 統計資訊:    [8] =>     資料包: 已發送 = 4,已接收 = 4,丟失 = 0 (0% 丟失),    [9] => 往返行程的估計時間(以毫秒為單位):    [10] =>     最短 = 0ms,最長 = 0ms,平均 = 0ms)

try doing it!

PHP 使用 ping 命令ping ip

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.