当我使用ssh2_exec()
执行命令enable时,我无法加载页面,因为它正在等待密码。
我试图做ssh2_exec(connection,'password')
问题依然存在。
我的问题是如何把启用密码? 这里是我的代码:插入启用密码ssh2 PHP
<?php
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
// log in at server1.example.com on port 22
if(!($con = ssh2_connect("9.0.0.1", 22))){
echo "fail: unable to establish connection\n";
} else {
// try to authenticate with username root, password secretpassword
if(!ssh2_auth_password($con, "mehdi", "123")) {
echo "fail: unable to authenticate\n";
} else {
// allright, we're in!
echo "okay: logged in...\n";
// execute a command
if (!($stream = ssh2_exec($con, 'enable'))) {
echo "fail: unable to execute command\n";
} else {
// collect returning data from command
stream_set_blocking($stream, true);
ssh2_exec($con, 'PASSWORD');
$data = "";
while ($buf = fread($stream,4096)) {
$data .=PHP_EOL. date("Y-m-d H:i:s ").$buf;
$data .= PHP_EOL."------------------------------------------------------------------------------------------------------------------------\n";
}
echo $data;
$fh = fopen("log".date("Y-m-d").".txt", 'a+') or die("can't open file");
fwrite($fh, $data);
fclose($fh);
fclose($stream);
}
}
}
?>
PS:我试图配置Cisco路由器
您正在寻找['ssh2_auth_password();'(http://de2.php.net/manual/en/function.ssh2-auth-password.php) – DanFromGermany 2014-08-27 14:04:54
没有,当我执行命令“enable”进入特权模式 – Lizinh 2014-08-27 14:20:14
没有命令'enable'。请链接到官方文档,通过'enable'显示您的意思,并在问题中提供一些代码。没有这些信息,没有人能帮助你。 – DanFromGermany 2014-08-27 14:25:01