2017-02-07 19 views
0

SSHを最初に接続し、次に資格情報でTelnetを開く必要のあるツールを書いています。パテから手動でSSHに接続してコマンドを実行できます。SSH接続によるTelnetの確立

telnet localhost 21000 

これは私に資格情報を要求します。しかし、コードでこれを行うと、何も起こりません。私はMinimalisticTelnetを試しましたが、私のマシンからtelnetを確立しました。私はこれにしたくない。 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); 

何をすべきか、私はユーザー名とパスワードの要求で、telnetのプロンプトを読み取ることができますが、ときに私は、ユーザー名とパスワードを送信すると、各shell.writeline

+0

これはすでにわかっています。 – nuriselcuk

1

を動作しないようです、

を入れています
system.threading.sleep(1500) 

ユーザー名とパスワードの入力を求める時間があります。

関連する問題