php 根据ping的返回值判断电脑是否在线
根据ping的返回值判断电脑是否在线 [代码片段(33行)]
<?php $key="Request timed out."; $kkk=array( "name3" =>array("192.168.0.118","王五","行政",), "name4" =>array("192.168.0.140","李四","财务",), "name5" =>array("192.168.0.10","张三","后勤",), ); echo "<table border='1' height=50% width=520 cellpadding=0 cellspacing='0' valign='top' bgcolor='#6666FF'>"; echo "<th align = 'center'>姓名</th>"; echo "<th align = 'center'>部门</th>"; echo "<th align = 'center'>状态</th>"; foreach ($kkk as $ddd) { unset($result); exec("ping $ddd[0] -n 1",$result,$rval); if ($result[3] == $key){ echo "<tr> \\n"; echo "<td align='center'>$ddd[1]</td>"; echo "<td align='center'>$ddd[2]</td>"; echo "<td align='center' bgcolor='#000000'><font color='#FF00FF'>离线</font></td>"; echo "</tr>"; }else{ echo "<tr> \\n"; echo "<td align='center'>$ddd[1]</td>"; echo "<td align='center'>$ddd[2]</td>"; echo "<td align='center'><font color='#0033FF'>在线</font></td>"; echo "</tr>"; } } ?> //该片段来自于http://outofmemory.cn
精彩图集
精彩文章