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

被折叠的 条评论
为什么被折叠?



