大家好,
最近想制作一个B/S结构的WEB版DOS。
其中遇到远程协议(SSH、TELNET)指令执行的问题,因此想借用以上两个开源项目。
问题:
当我运行开源项目示例时,SSH到服务器后,接收到的返回中,所有中文都是乱码。
请高手赐教。
static void Main(string[] args)
{
try
{
//Create a new JSch instance
JSch jsch = new JSch(); //Prompt for username and server host
Console.WriteLine("Please input hostname:");
String host = Console.ReadLine();
Console.WriteLine("Please input username:");
String user = Console.ReadLine();
Console.WriteLine("Please input password:");
String pwd = Console.ReadLine(); //Create a new SSH session
Session session = jsch.getSession(user, host, 22); // username and password will be given via UserInfo interface.
UserInfo ui = new ShellUserInfo();
ui.setPassword(pwd);
session.setUserInfo(ui); //Connect to remote SSH server
session.connect(); //Open a new Shell channel on the SSH session
Channel channel = session.openChannel("shell"); //Redirect standard I/O to the SSH channel
channel.setInputStream(Console.OpenStandardInput());
channel.setOutputStream(Console.OpenStandardOutput()); //Connect the channel
channel.connect(); Console.WriteLine("-- Shell channel is connected using the {0} cipher",
session.getCipher()); //Wait till channel is closed
while (!channel.isClosed())
{
System.Threading.Thread.Sleep(500);
} //Disconnect from remote server
channel.disconnect();
session.disconnect(); }
catch (Exception e)
{
Console.WriteLine(e);
}
}
最近想制作一个B/S结构的WEB版DOS。
其中遇到远程协议(SSH、TELNET)指令执行的问题,因此想借用以上两个开源项目。
问题:
当我运行开源项目示例时,SSH到服务器后,接收到的返回中,所有中文都是乱码。
请高手赐教。
static void Main(string[] args)
{
try
{
//Create a new JSch instance
JSch jsch = new JSch(); //Prompt for username and server host
Console.WriteLine("Please input hostname:");
String host = Console.ReadLine();
Console.WriteLine("Please input username:");
String user = Console.ReadLine();
Console.WriteLine("Please input password:");
String pwd = Console.ReadLine(); //Create a new SSH session
Session session = jsch.getSession(user, host, 22); // username and password will be given via UserInfo interface.
UserInfo ui = new ShellUserInfo();
ui.setPassword(pwd);
session.setUserInfo(ui); //Connect to remote SSH server
session.connect(); //Open a new Shell channel on the SSH session
Channel channel = session.openChannel("shell"); //Redirect standard I/O to the SSH channel
channel.setInputStream(Console.OpenStandardInput());
channel.setOutputStream(Console.OpenStandardOutput()); //Connect the channel
channel.connect(); Console.WriteLine("-- Shell channel is connected using the {0} cipher",
session.getCipher()); //Wait till channel is closed
while (!channel.isClosed())
{
System.Threading.Thread.Sleep(500);
} //Disconnect from remote server
channel.disconnect();
session.disconnect(); }
catch (Exception e)
{
Console.WriteLine(e);
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货