Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: ssh to debian, then telnet to other devices

$
0
0
hi im elhave and im newbie in coding

need help. i have same issue
  1. i want to connect to ssh server first.
  2. from that ssh server i want to telnet to other server/cisco router
i have succesfully got into ssh server.
but the telnet command, and any other command that return as question from the ssh server or ask back an input from me just don't work.

here's how i write the code



class Program
{
    static void Main(string[] args)
    {
        string userName = "elhave";
        string serverName = "192.168.1.1";//mysshserver
        string password = "mypass";


        var keyboardAuthMethod = new KeyboardInteractiveAuthenticationMethod(userName);
        keyboardAuthMethod.AuthenticationPrompt += delegate(Object senderObject, AuthenticationPromptEventArgs eventArgs) {
            foreach (var prompt in eventArgs.Prompts){
                        if (prompt.Request.Equals("Password: ", StringComparison.InvariantCultureIgnoreCase)) {
                            prompt.Response = password;
                        }                 
            }             
        };             

        var passwordAuthMethod = new PasswordAuthenticationMethod(userName, password);
        var connectInfo = new ConnectionInfo(serverName, userName, passwordAuthMethod, keyboardAuthMethod);

        string hasil = "";
        using (var serverConnection = new SshClient(connectInfo))
        {
            serverConnection.Connect(); 
            var command = serverConnection.RunCommand("who");//inisialization
            while (true)
            {
                command.Dispose();
                nextcommand = Console.ReadLine();
                command = serverConnection.RunCommand(nextcommand);
                Console.Write(command.Result);
                if (nextcommand == "break") {

                    break;
                }
            }



        }
    }
}
}


i expect the app to work like putty. read command, run command, and display the result. but seems like i cant perform it with this code.
here i type man command that will return question from server.
on putty it worked but on my application it did work.
Image

Viewing all articles
Browse latest Browse all 1729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>