简体   繁体   English

php ssh phpseclib output 多行

[英]php ssh phpseclib output over multiple lines

I would like to execute commands on remote server via ssh and i use phpseclib.我想通过 ssh 在远程服务器上执行命令,我使用 phpseclib。 If i run the command, all the output is in one line (because its a string).如果我运行命令,所有 output 都在一行中(因为它是一个字符串)。

I would have the same output as in the local shell我将拥有与本地 shell 相同的 output

Current var_dump():当前 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 "

Current Output:当前 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 

Expected Output:预期 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

Current Code:当前代码:

<?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');

?>

You can use <pre>您可以使用<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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM