2

I need to ssh to debian server and then from this server telnet to other (cisco) devices, run some commands and read response.

I've started writing C# application to connect to ssh server (using SSH.NET library), but how should I continue with telneting from this server?

Should I write C or Perl program that would telnet to device and I would execute this program remotely? Isn't there any easier way like bash script? Or maybe asynchronous ssh connection that would allow me to execute telnet program on debian server and control it remotely?

Buksy
  • 11,571
  • 9
  • 62
  • 69

1 Answers1

3

As SSH allows tunnelling, perhaps you could initiate the SSH session, create a tunnel for the telnet part and then you could issue the telnet commands from the same C# program through the tunnel to the Cisco devices.

If you decide to go with this approach, this question about .Net Telnet libraries might be useful

Community
  • 1
  • 1
Andrew
  • 12,991
  • 15
  • 55
  • 85
  • tunneling sounds good, SSH.NET library Im using has port forwarding option, I will try it, but I have one more question, does a ssh client tell the server to listen on new port and forward the connection, or is this implemented by client somehow (I have no idea how this could be done). So tunneling is part of protocol and should be supported by every ssh server? – Buksy Sep 05 '12 at 15:01
  • @Buksy _"does a ssh client tell the server to listen on new port and forward the connection"_ - I don't know the details of how it works, but if you're concerned that your SSH server might not support it, you can test the tunnelling interactively with something like [PuTTY](http://www.chiark.greenend.org.uk/~sgtatham/putty/) then fire up a telnet client to test the tunnel – Andrew Sep 05 '12 at 15:25
  • Thank you, it works :) ... I ssh on debian server and run this command `ssh -N -g -L 10500:remoteHost:23 localhost` (first I had to set automatic authentication using [ssh-keygen](http://serverfault.com/questions/320382/ssh-public-key-authentication-issue) ). Im able to telnet to device using this tunnel – Buksy Sep 05 '12 at 18:42
  • @Buksy is there any way that you could share your solution with me in more detail? I am trying to do the exact same thing (SSH to a server and then Telnet and then issue commands). However I am quite new to this and don't understand all of the concepts exactly. Do you have any example code (other than the command above) that you could share? – Corey Burnett Sep 14 '12 at 16:15
  • Sorry for late reply, if u're still interested, I can upload my solution somewhere, unfortunately, it hasnt been completely finished because it has been denied by my bosses. But it works ;) – Buksy Sep 25 '12 at 08:04