我正在尝试使用 phpseclib 的 NET_SSH2 库连接到 HP 交换机。只是为了测试/开始,我正在尝试登录,然后在交换机上运行“显示接口简要”命令。但是在它让我登录后,我收到一条错误消息:
SSH command execution is not supported.
这是代码:
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . '../phpseclib');
include('Net/SSH2.php');
define('NET_SSH2_LOGGING', true); //turn on logging.
$ssh = new Net_SSH2('10.10.10.10'); //starting the ssh connection to localhost
if (!$ssh->login('', 'password')) { //if you can't log on...
exit('Login Failed');
}
else {
echo 'logged in<br>';
}
echo 'Attempting command: <br>';
$output = $ssh->exec('show interfaces brief');
echo $output.'<br>';
echo 'Error message is: <br>';
$log = $ssh->getLog(NET_SSH2_LOG_COMPLEX);
foreach ($log as $logitem) {
echo $logitem.'<br>';
}
?>
这返回的输出是:
logged in
Attempting command:
Notice: Connection closed prematurely in /var/www/phpseclib/Net/SSH2.php on line 1941
SSH command execution is not supported.
Error message is:
<-
->
<- NET_SSH2_MSG_KEXINIT (0.0015s)
-> NET_SSH2_MSG_KEXINIT (0s)
-> NET_SSH2_MSG_KEXDH_INIT (0s)
<- NET_SSH2_MSG_KEXDH_REPLY (0.5123s)
-> NET_SSH2_MSG_NEWKEYS (0s)
<- NET_SSH2_MSG_NEWKEYS (0s)
-> NET_SSH2_MSG_SERVICE_REQUEST (0s)
<- NET_SSH2_MSG_SERVICE_ACCEPT (0.1962s)
-> NET_SSH2_MSG_USERAUTH_REQUEST (0.0001s)
<- NET_SSH2_MSG_USERAUTH_BANNER (0.0014s)
<- NET_SSH2_MSG_USERAUTH_SUCCESS (0.0392s)
-> NET_SSH2_MSG_CHANNEL_OPEN (0s)
<- NET_SSH2_MSG_CHANNEL_OPEN_CONFIRMATION (0.0204s)
-> NET_SSH2_MSG_CHANNEL_REQUEST (0s)
<- NET_SSH2_MSG_CHANNEL_SUCCESS (0.1011s)
<- NET_SSH2_MSG_CHANNEL_DATA (0s)
-> NET_SSH2_MSG_CHANNEL_DATA (0s)
<- NET_SSH2_MSG_CHANNEL_EOF (0s)
<- NET_SSH2_MSG_CHANNEL_REQUEST (0s)
<- NET_SSH2_MSG_CHANNEL_CLOSE (0s)
Notice: Connection closed prematurely in /var/www/phpseclib/Net/SSH2.php on line 1941
ssh2.php 中的第 1941 行是您在下面看到的“user_error”行:
function _send_binary_packet($data)
{
if (feof($this->fsock)) {
user_error('Connection closed prematurely', E_USER_NOTICE);
return false;
}
到目前为止我所做的:
- 我已经通过 ssh 手动登录并确保我可以运行相同的命令。
- 我已经浏览了交换机的 web 配置页面,以确保我不需要为 ssh 打开其他任何东西。
- 我一直在检查 phpseclib 的论坛是否有任何类似的问题。
我正在使用 phpseclib 的 1.53 2010/10/24 01:24:30 版本。
任何帮助,将不胜感激。谢谢。