Linux下PHP调用wmic获取远程Windows监控信息及解析返回结果

这段PHP代码演示了如何通过WMIC命令连接到远程Windows主机(192.168.174.1),并以管理员身份(username: administrator, password: pass)获取进程列表。它首先执行命令,然后打印输出和返回代码。如果执行成功,它将遍历输出并分解每个进程信息。请注意,代码中使用了`explode()`替换已废弃的`split()`函数。
摘要由CSDN通过智能技术生成
<?php

$output = null;
$code = null;
$command = "/usr/bin/wmic -U administrator%pass //192.168.174.1 'select caption, name, parentprocessid, processid from win32_process'";
exec($command, $output, $code);
print_r($output);
print_r($code);
if ($code == 0) {
    $round = count($output);
    echo "\nThe number of elements are $round \n";
    if ($round > 1) {
        echo "Looping using for: \n";
        for ($n = 1; $n < $round; $n++) {
            echo $output[$n], "\n";
            $item = split("\|", $output[$n]);
            $round_item = count($item);
            for ($i = 0; $i < $round_item; $i++) {
                print "$item[$i] <br />";
            }
        };
    }
}
?>

PHP7,使用 explode() 替代split() 

<?php

$output = null;
$code = null;
$command = "/usr/bin/wmic -U administrator%pass, //192.168.174.1 'select caption, name, parentprocessid, processid from win32_process'";
exec($command, $output, $code);
print_r($output);
print_r($code);
if ($code == 0) {
    $round = count($output);
    echo "\nThe number of elements are $round \n";
    if ($round > 1) {
        echo "Looping using for: \n";
        for ($n = 1; $n < $round; $n++) {
            echo $output[$n], "\n";
            $item = explode("\|", $output[$n]);
            $round_item = count($item);
            for ($i = 0; $i < $round_item; $i++) {
                print "$item[$i] <br />";
            }
        };
    }
}
?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值