php和ping命令的结合

2018-04-05  本文已影响8人  CSeroad

IPV4地址协议预留了3个IP地址段,作为私有地址。

A类:10.0.0.0--10.255.255.255

B类:172.16.0.0--172.31.255.255

C类:192.168.0.0--192.168.255.255

以整个15网段进行遍历来有探测网关,从而判断网络的划分,是一件有意思的事情,为后来的有料做铺垫

用来测试各个网关

代码如下:

<?php

header("Content-type: text/html; charset=utf-8");

set_time_limit(0);

$time1 = microtime(true);

for ($n=1; $n < 255; $n++){

$ping="192.168.".$n.".1";

$t1 = microtime(true);

exec("ping -n 1 $ping",$list);

$t2 = microtime(true);

$time=round($t2-$t1,3);

if($time<1){

echo $ping."-----时间为:".$time."<br/>";

}else{

echo $ping."------ping不通"."<br/>";

}

unset($list);//清空数组

}

$time2 = microtime(true);

$times=round($time2-$time1,3);//代码执行时间

echo "<hr/>"."总耗时:".$times;

?>

附图:

时间
上一篇 下一篇

猜你喜欢

热点阅读