Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获得';状态';通过PHP在网络上对机器的访问_Php_Html_Arrays_Ip_Ip Address - Fatal编程技术网

获得';状态';通过PHP在网络上对机器的访问

获得';状态';通过PHP在网络上对机器的访问,php,html,arrays,ip,ip-address,Php,Html,Arrays,Ip,Ip Address,我需要或多或少地获得一个表,该表报告本地网络上机器的IP,以及是否可以找到它 我已经设置了20台机器,都是静态IP地址,从192.168.1.111到192.168.1.120 如何检查机器是否“联机”,并将其状态报告回网页 目前,我正在这样做: <?php $nodes = array( "192.168.1.111", "192.168.1.112", "192.168.1.113", "192.168.1.11

我需要或多或少地获得一个表,该表报告本地网络上机器的IP,以及是否可以找到它

我已经设置了20台机器,都是静态IP地址,从
192.168.1.111到192.168.1.120

如何检查机器是否“联机”,并将其状态报告回网页

目前,我正在这样做:

<?php

    $nodes = array(
        "192.168.1.111",
        "192.168.1.112",
        "192.168.1.113",
        "192.168.1.114", // offline
        );

    $table = "";

    for($i = 0; $i < count($nodes); ++$i) {
        exec("ping -c 4 " . $nodes[$i], $output, $result);

        if ($result == 0) {
            // echo "Ping successful!";      
            $table += "<tr>";
            $table += "<td>Node " . $i . "</td>";
            $table += "<td> " . $nodes[$i] . "</td>";
            $table += "<td>Ready</td>";
            $table += "</tr>";

        } else {
            // echo "Ping unsuccessful!";     
            $table += "<tr>";
            $table += "<td>Node " . $i . "</td>";
            $table += "<td> " . $nodes[$i] . "</td>";
            $table += "<td>Offline</td>";
            $table += "</tr>"; 
        }
    }   

    echo $table;

?>

请尝试以下操作,或使用/bin/ping-n3

<?php
function pingAddress($ip) {
    $pingresult = exec("/bin/ping -n 3 $ip", $outcome, $status);
    if (0 == $status) {
        return = True;
    } else {
        return = False;
    }
}

pingAddress("127.0.0.1");
?>

<?php
function pingAddress($ip) {
    $pingresult = exec("/bin/ping -n 3 $ip", $outcome, $status);
    if (0 == $status) {
        return = True;
    } else {
        return = False;
    }
}

pingAddress("127.0.0.1");
?>