如何使用php和ssh切换VLAN

时间:2019-04-09 13:41:22

标签: php linux xampp phpseclib vlan

我正在尝试打开/切换VLAN(使用php)。在命令行上效果很好:

raphael@WST501749:~/Dokumente/Quellcode/CW$ ./scriptIN.sh
Pseudo-terminal will not be allocated because stdin is not a terminal.

(M4300-28G-PoE+) >enable

(M4300-28G-PoE+) #configure

(M4300-28G-PoE+) (Config)#interface 1/0/2

(M4300-28G-PoE+) (Interface 1/0/2)#vlan participation include 40

(M4300-28G-PoE+) (Interface 1/0/2)#vlan tagging 40

(M4300-28G-PoE+) (Interface 1/0/2)#exit

下一步:通过PHP脚本执行相同的操作。我尝试了以下方法:

<?php
set_include_path(get_include_path().PATH_SEPARATOR.'/home/raphael');
include('Net/SSH2.php'); 
$ssh = new Net_SSH2('172.18.9.11'); 
if (!$ssh->login('admin', 'testcode')) { 
   exit('Login Failed'); 
}else{ 
    echo "connected".'<br>'; 
    echo $ssh->exec('enable').'<br>';
    echo 'enable done<br>';
    echo $ssh->exec('configure').'<br>';
    echo 'configure done <br>';
    echo $ssh->exec('interface 1/0/2').'<br>';
    echo 'interface 1/0/2 done <br>';
    echo $ssh->exec('vlan participation include 40').'<br>';
    echo 'include done<br>';
    echo $ssh->exec('vlan tagging 40').'<br>';
    echo 'tagging done<br>';
    echo $ssh->exec('exit').'<br>';
    echo 'exit done <br>';
}

?>

我得到以下输出:

connected
(M4300-28G-PoE+) >
enable done
(M4300-28G-PoE+) >
configure done 
(M4300-28G-PoE+) >
interface 1/0/2 done 
(M4300-28G-PoE+) >
include done
(M4300-28G-PoE+) >
tagging done

Notice: Unable to open channel in /home/raphael/Net/SSH2.php on line 3963

exit done 

似乎执行了命令,但没有任何效果。 opt / lampp / logs中的error_log没有提供其他信息。

0 个答案:

没有答案