[英]php ssh phpseclib output over multiple lines
我想通过 ssh 在远程服务器上执行命令,我使用 phpseclib。 如果我运行命令,所有 output 都在一行中(因为它是一个字符串)。
我将拥有与本地 shell 相同的 output
当前 var_dump():
string(291) "Starting Nmap 7.80 ( https://nmap.org ) at 2020-04-10 10:08 CEST Nmap scan report for dns.google (8.8.8.8) Host is up (0.0037s latency). Not shown: 998 filtered ports PORT STATE SERVICE 53/tcp open domain 443/tcp open https Nmap done: 1 IP address (1 host up) scanned in 4.59 seconds "
当前 Output:
Starting Nmap 7.80 ( https://nmap.org ) at 2020-04-10 10:14 CEST Nmap scan report for dns.google (8.8.8.8) Host is up (0.0036s latency). Not shown: 998 filtered ports PORT STATE SERVICE 53/tcp open domain 443/tcp open https Nmap done: 1 IP address (1 host up) scanned in 4.50 seconds
预期 Output:
Starting Nmap 7.80 ( https://nmap.org ) at 2020-04-10 10:14 CEST
Nmap scan report for dns.google (8.8.8.8)
Host is up (0.0037s latency).
Not shown: 998 filtered ports
PORT STATE SERVICE
53/tcp open domain
443/tcp open https
当前代码:
<?php
include 'vendor/autoload.php';
$ssh = new \phpseclib3\Net\SSH2('xxx.xxx.xxx.xxx');
if (!$ssh->login('root', 'password')) {
exit('Login Failed');
}
echo $ssh->exec('nmap 8.8.8.8');
?>
您可以使用<pre>
<?php
include 'vendor/autoload.php';
$ssh = new \phpseclib3\Net\SSH2('xxx.xxx.xxx.xxx');
if (!$ssh->login('root', 'password')) {
exit('Login Failed');
}
echo "<pre>";
echo $ssh->exec('nmap 8.8.8.8');
echo "</pre>";
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.