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

New Post: C# SSHNET ISSUE

$
0
0
Hi,

I've been trying to make this work for a few days now but keep running into problems. I'm trying to make an application for college project to log onto a modem by SSH client and make it do a reboot with a windows form button.

Some information:
MODEM ip: 192.168.1.1

How I do it now:
  1. Putty
  2. 168.1.1.1 Port 22
  3. Putty window says: "login as: "
  4. I say: "Administrator"
  5. Putty says: Administrator@192.168.1.1's password:
  6. I say: "" (empty, no password needed)
  7. Logged in
  8. I say: "system"
  9. I say: "reboot"
  10. Modem is rebooted
Now i tried to script this with normal ip and password, with puttygen and key and convert key to open ssl,....

NOTE: seems that the modem only accepts keyboard interactive login so this is my code:
   KeyboardInteractiveAuthenticationMethod keybAuth = new KeyboardInteractiveAuthenticationMethod("Administrator");
            PasswordAuthenticationMethod passAuth = new PasswordAuthenticationMethod("Administrator", "");

            keybAuth.AuthenticationPrompt += new EventHandler<AuthenticationPromptEventArgs>(HandleKeyEvent);
            ConnectionInfo connectionInf = new ConnectionInfo("192.168.1.1", 22, "Administrator", passAuth, keybAuth);

            SshClient client = new SshClient(connectionInf);
            client.Connect();
            client.RunCommand("system");
            client.RunCommand("reboot");
and
  void HandleKeyEvent(Object sender, AuthenticationPromptEventArgs e)
        {
            foreach (AuthenticationPrompt prompt in e.Prompts)
            {
                if (prompt.Request.IndexOf("Password: ", StringComparison.InvariantCultureIgnoreCase) != -1)
                {
                    prompt.Response = "";
                }
            }
        }

Viewing all articles
Browse latest Browse all 1729

Trending Articles