當我使用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