在 Windows 中使用 PHP 中的 Ping 多个 IP

Pinging Multiple IPs using in PHP in Windows

我想在 Windows 基于 Apache 服务器上使用 PHP 中的 Exec 命令 Ping 从 HTML 表单获取的 2 个或更多 IP。

<?php 
if(isset($_REQUEST['go'])){
    $ips=implode(" ",$_REQUEST['ips']);
    $total=count($ips);

        for ($i=1; $i<=$total; $i++){
        exec ("ping -n 2".$ips, $ping_output, $value);
        echo $ping_output;
        }
}
?>


<form method="post" enctype="multipart/form-data">
<label>Enter First IP</label><br/>
<input type="text" name="ips[]" placeholder="192.168.0.1" required="true" /><br/>
<label>Enter Second IP</label><br/>
<input type="text" name="ips[]" placeholder="127.0.0.1" required="true" /><br/>
<button type="submit" name="go">Get Results</button>
</form>

当我 运行 这个脚本进入无限循环并且除了 Processing 什么都不显示。 我只想显示针对其 IP 的 IP ping 结果是否成功。

首先创建 Ping 单个 IP 地址的函数

function pingIp($ip) {
    exec ("ping -n 2 ".$ip, $ping_output, $value);
    return $ping_output;
}
if(isset($_REQUEST['go'])){
//$arr = array('127.0.0.1','127.0.0.9','46.101.113.87','159.203.96.186');
  $arr =$_REQUEST['ip'];
for($i=0; $i<count($arr); $i++){
    ?>
    <pre>
    <?php
    print_r(pingIp($arr[$i]));
    echo('<br/><br/>');
}
}

然后从表单获取 IP 并按照给定示例调用该函数。