2017-02-07 3 views
0

SSH를 먼저 연결하고 자격 증명이있는 텔넷을 열어야하는 도구를 작성 중입니다. Putty에서 수동으로 SSH를 연결 한 다음 명령을 실행합니다.SSH 연결을 통한 텔넷 설정

telnet localhost 21000 

이것은 자격 증명을 묻습니다. 그러나 코드에서 이렇게하면 아무 일도 일어나지 않습니다. MinimalisticTelnet을 시도했지만 컴퓨터에서 텔넷을 설정했습니다. 나는 이것을 원하지 않는다. Telnet 연결은 SSH 연결에서 수행되어야합니다.

내 코드는 다음과 같습니다.

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using Renci.SshNet; 
using MinimalisticTelnet; 

namespace Ssh_Net 
{ 
    class Program 
    { 

     static void Main(string[] args) 
     { 
      String host = "54.88.81.210"; 
      String username = "root"; 
      String password = "abcd1234"; 
      int port = 22; 

      ForwardedPortDynamic tunnelPort; 

      // Setup SSH with Credentials 
      ConnectionInfo ConnNfo = new ConnectionInfo(host, port, username, 

       new AuthenticationMethod[] { 

         /* Password based authentication */ 
         new PasswordAuthenticationMethod(username, password) 
       } 
      ); 


      // Instantly execute a shell command 

      using (var sshclient = new SshClient(ConnNfo)) 
      { 
       sshclient.Connect(); 
       Console.WriteLine("Connecting"); 

       if (sshclient.IsConnected) 
       { 
        try 
        { 
         Console.WriteLine(sshclient.RunCommand("telnet localhost 21000").Execute()); 

        } 
        catch (Exception e) 
        { 
         Console.Write(e.ToString()); 
        } 
       } 

       Console.ReadLine(); 
       sshclient.Disconnect(); 

      } 


     } 


    } 
} 

답변

0

동일한 문제가 있습니다. 이것은 내가 사용자 이름과 암호를 요청,

sshMaster = new SshClient(host, sshUserSSL, sshPwdSSL); 
sshMaster.Connect(); 
ShellStream shell = sshMaster.CreateShellStream("master", 80, 24, 800, 600, 1024); 
shell.WriteLine(" telnet localhost 21000"); 
shell.WriteLine(USERNAME); 
shell.WriteLine(PASSWORD); 

내가 텔넷 프롬프트를 읽을 수 없지만, 내가 이름을 보내고 암호가 각 shell.writeline

+0

이것은 이미 보았습니다. – nuriselcuk

1

작동하지 않는 것 같다 때,

을 넣어 것입니다
system.threading.sleep(1500) 

사용자 이름과 암호를 묻는 메시지가 표시됩니다.