Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.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将Linux命令的结果输出到表中_Php_Html_Arrays_Linux_Html Table - Fatal编程技术网

使用PHP将Linux命令的结果输出到表中

使用PHP将Linux命令的结果输出到表中,php,html,arrays,linux,html-table,Php,Html,Arrays,Linux,Html Table,我正在开发一个在Raspberry Pi上运行的捕获式门户,并使基础工作正常,但我现在在创建一些管理页面时遇到了障碍 我基本上是想用HTML/PHP创建一个表,这样我就能够从服务中“踢”用户。我已经准备好了一个脚本来实现这一点,但我正在努力将exec语句的结果回显到表中 这就是我成功做到的程度: <?php $mac = array(); exec( "sudo iptables -L -t mangle | grep MAC | cut -d' ' -f37", $mac

我正在开发一个在Raspberry Pi上运行的捕获式门户,并使基础工作正常,但我现在在创建一些管理页面时遇到了障碍

我基本上是想用HTML/PHP创建一个表,这样我就能够从服务中“踢”用户。我已经准备好了一个脚本来实现这一点,但我正在努力将exec语句的结果回显到表中

这就是我成功做到的程度:

<?php
    $mac = array();
    exec( "sudo iptables -L -t mangle | grep MAC | cut -d' ' -f37", $mac );
    $ip = array();
    exec( "sudo arp -i eth1 -a | cut -d' ' -f2 | tr -d '()'", $ip );
?>
<style>
    table, tr, td, th
    {
        font-family:verdana,sans-serif;
        font-size:11px;
        border:1px solid black;
        border-collapse:collapse;
        padding:5px;
    }
</style>
<html>
    <body>
        <div style="font-family:verdana,sans-serif;font-size:11px;">
            Currently connected:<br><br>
            <table>
                <tr>
                    <th>MAC</th>
                    <th>IP</th>
                </tr>
                <tr>
                    <td><?php echo implode("<br />", $mac); ?></td>
                    <td><?php echo implode("<br />", $ip); ?></td>
                </tr>
            </table>
        </div>
    </body>
</html>

通过以下方式实现此功能:

<?php
    $mac = array();
    exec( "sudo iptables -L -t mangle | grep MAC | cut -d' ' -f37", $mac );
    $ip = array();
    exec( "sudo arp -i eth1 -a | cut -d' ' -f2 | tr -d '()'", $ip );
?>

<style>
    table, tr, td, th
    {
        font-family:verdana,sans-serif;
        font-size:11px;
        border:1px solid black;
        border-collapse:collapse;
        padding:5px;
    }
</style>
<html>
    <body>
        <table>
            <tr>
                <th>MAC</th>
                <th>IP</th>
            </tr>
            <?php foreach(array_combine($ip, $mac) as $ipaddress => $macaddress){
    echo "<tr><td>".$ipaddress."</td><td>".$macaddress."</td></tr>";
}
?>
        </table>
    </body>
</html>

也许您可以从iptables&arp命令链发布几行输出?在PHP中grep和cut之后,iptables的输出显示为:00:15:5D:10:25:11 00:15:5D:10:25:02,使用内爆中断,这将它们放在单独的行上,但我希望它们转到表中的单独行。带有cut和tr的arp命令的输出类似,只是两个IP地址以空格分隔,而不是以新行分隔,内爆将它们放在不同的行上。
<?php
    $mac = array();
    exec( "sudo iptables -L -t mangle | grep MAC | cut -d' ' -f37", $mac );
    $ip = array();
    exec( "sudo arp -i eth1 -a | cut -d' ' -f2 | tr -d '()'", $ip );
?>

<style>
    table, tr, td, th
    {
        font-family:verdana,sans-serif;
        font-size:11px;
        border:1px solid black;
        border-collapse:collapse;
        padding:5px;
    }
</style>
<html>
    <body>
        <table>
            <tr>
                <th>MAC</th>
                <th>IP</th>
            </tr>
            <?php foreach(array_combine($ip, $mac) as $ipaddress => $macaddress){
    echo "<tr><td>".$ipaddress."</td><td>".$macaddress."</td></tr>";
}
?>
        </table>
    </body>
</html>
<style>
    table, tr, td, th
    {
        font-family:verdana,sans-serif;
        font-size:11px;
        border:1px solid black;
        border-collapse:collapse;
        padding:5px;
    }
</style>
<html>
    <body>
        <table>
            <tr>
                <th>MAC</th>
                <th>IP</th>
            </tr>
            <tr><td>10.0.128.107</td><td>00:15:5D:10:25:11</td></tr><tr><td>10.0.128.106</td><td>00:15:5D:10:25:02</td></tr>        </table>
    </body>
</html>