SSH into Router to make changes

0
Im trying to use the SSH tool to be able to change a router ip via SSH, it is very simple via putty and port 22. We have a lot of the routers that we want to automate some of those configurations. I've tried some of your examples but can't seem to get any to work. Below is just a basic test with a test box where I just want to see the interface information but it fails at couple of places where there is hostkey prompt that should indicate yes or no to accept the key but I don't see it . I have a form with button and the SshTerminalControl1 on it, Not sure what else I'm missing. I don't see any information in the terminal control either. Imports ComponentPro.Net Imports ComponentPro.Net.Terminal Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click HandleHostKeyVerifyingEvent() End Sub Public Sub HandleHostKeyVerifyingEvent() Try ' Create a new instance. Dim client As New SshClient() ' AddHandler client.HostKeyVerifying, AddressOf client_HostKeyVerifying 'Fails here client.Connect("172.16.0.1", 22) ' Or you can specify the SFTP port with ' client.Connect("myserver", 22); ' Authenticate. client.Authenticate("admin", "password") ' Do something here... ' ... Dim shell As TerminalShell = client.CreateShell(True) ' Print any welcome messages, if available. Console.WriteLine(shell.ReadToEnd()) ' Send 'Showing the interface information' command. shell.SendCommand("show interface x1") Console.WriteLine(shell.ReadToEnd()) ' Disconnect. client.Disconnect() Catch ex As Exception MessageBox.Show(ex.ToString) End Try End Sub Private Sub client_HostKeyVerifying(ByVal sender As Object, ByVal e As HostKeyVerifyingEventArgs) ' Print out the fingerprint info. Console.Write(String.Format("Host key: {0}. Do you want to accept this host key?(y/n):", e.HostKey.ToString())) Dim answer As String = Console.ReadLine() ' Accept the fingerprint if user entered "y". e.Accept = answer.ToLower() = "y" 'Fails here saying something is null' End Sub End Class The commands I want to send to the Router is in order below right after you would login is: - interface x1 - ip-assignment WAN static - ip - netmask - gateway - dns primary - commit - exit - exit - exit I need to translate these commands into your SSH tool via vb.net. If this all passes then I can move forward to purchasing your tool. Thanks
edited 10/29/2018 4:16:20 PM
asked 10/26/2018 4:41:25 PM
  I tried that too. I got a windows form , one button and the vterminal control placed on the form. Here is the code. Imports ComponentPro.Net Imports ComponentPro.Net.Terminal Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ' Create an SshClient object. Dim client As New SshClient() Try client.Timeout = 25000 ' Connect to the specified server. client.Connect("172.16.0.1", 22) ' Authenticate. client.Authenticate("admin", "password") 'Fails right here, says server disconnects Dim shell As TerminalShell = client.CreateShell(True) shell.SendCommand("show interface x1") ' Repeat while the command is running. Do While shell.IsCommandRunning ' Read response until end or until '? ' is encountered. Dim result As String = shell.ReadToEnd("? ") If result.EndsWith("? ") Then ' Send Y for yes. shell.SendCommand("y") End If Loop Catch ex As Exception 'Console.WriteLine(vbLf & "An exception occurred: {0}", ex.Message) MessageBox.Show(ex.ToString) Finally ' Close the connection. client.Disconnect() End Try End Sub End Class Get error server disconnects jilan3109 10/27/2018 5:29:20 PM
add a comment

1 Answers

0
In case the Ssh Shell class does not work for your router, you can use the VirtualTerminal class. Please check this topic out: [http://doc.componentpro.com/ComponentPro-Terminal/Starting-a-VirtualTerminal][1] [1]: http://doc.componentpro.com/ComponentPro-Terminal/Starting-a-VirtualTerminal
 
answered 10/27/2018 4:28:37 AM
add a comment

Your Answer

Not the answer you're looking for? Browse other questions tagged license ultimate terminal emulation or ask your own question.