ShellHelp shell = new ShellHelp();
//連接路由器成功
if (shell.OpenShell("172.169.81.1", "root", "dnkty218"))
{
shell.Shell("ena");//進入配置模式命令
shell.Shell("dnkty109");//輸入進入配置模式的密碼 問題就出在這里,好像無法將密碼輸入,回顯的也不提示密碼錯誤,就好 像沒有輸入一樣,其它都命令都沒有問題
string info = shell.GetAllString();//獲取回傳結果
Console.WriteLine(info);
shell.Close();//關閉連接
}
Console.ReadLine();
public bool OpenShell(string host, string username, string pwd)
{
try
{
////Redirect standard I/O to the SSH channel
inputstream = new Tamir.SharpSsh.SshStream(host, username, pwd);
///我手動加進去的方法。。為了讀取輸出資訊
inputstream.set_OutputStream(outputstream);
return inputstream != null;
}
catch { throw; }
}
問題就出在再次輸入配置模式密碼的地方,其它命令都沒有問題,下面是送入命令的代碼
public void Write(String data)
{
//Encoding.ASCII.GetBytes(password);
data += "\r";
//Write( Encoding.Default.GetBytes( data ) );
Write(Encoding.ASCII.GetBytes(data));
Flush();
}
uj5u.com熱心網友回復:
其它命令都可以,就是進行配置模式輸入密碼有問題,難道送入的密碼就根本沒有執行?因為回顯獲取的還是輸入密碼的界面,只是多了1行而已,類似在輸入密碼的界面回車了一次uj5u.com熱心網友回復:
經自己確認,送入密碼的地方,其實只送入了回車符,密碼根本就沒有送入,Write(Encoding.ASCII.GetBytes(data),難道編碼有問題?但是試了幾個編碼,還是一樣,而且ASCII,我telnet下是可以成功送入的轉載請註明出處,本文鏈接:https://www.uj5u.com/net/102042.html
標籤:C#
