簡體   English   中英

php ssh phpseclib output 多行

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM