0

I'm trying to connect to a Cisco Switch with SSH and ruby. The problem is that I need to enter an empty 'login as' then it will ask me for an User Name and Password. On Putty I do like this: Putty

Here is how i have tried to connect with NET::SSH.

CISCO = "host" #Enter the IP address here 
USER = "operacao" #Enter username here 
PASS = "" #Enter password here 
tn = Net::SSH::Telnet::new("Host" => CISCO, "Timeout" => 60, "Prompt" => /^\login as:/ ) 
tn.cmd("\n") { |c| print c } 
tn.cmd("\n#{USER}") { |c| print c } 
tn.cmd(PASS) { |c| print c } 
tn.print("echo oi") { |c| print c } 
tn.close

Is there any way to do this with Ruby?

amalrik maia
  • 478
  • 5
  • 11
ruda
  • 181
  • 4
  • 14
  • Please post your code and the error messages. How could anyone help you if you don't show what're you doing? – amalrik maia May 03 '13 at 18:56
  • @amalrik maia my last try was: CISCO = "host" #Enter the IP address here USER = "operacao" #Enter username here PASS = "" #Enter password here tn = Net::SSH::Telnet::new("Host" => CISCO, "Timeout" => 60, "Prompt" => /^\login as:/ ) tn.cmd("\n") { |c| print c } tn.cmd("\n#{USER}") { |c| print c } tn.cmd(PASS) { |c| print c } tn.print("echo oi") { |c| print c } tn.close – ruda May 06 '13 at 13:13
  • @amalrikmaia: Next time, please mention in your edit comment where the code is coming from. Makes it easier for reviewers to see that it's a valid edit. – hammar May 06 '13 at 17:42

2 Answers2

0

From the screenshot I see "login as:" then "User Name:" and "Password". Since I'm not familiar with Cisco switches and when I watched the following video (http://www.youtube.com/watch?feature=player_detailpage&v=3v3Iw87vEQ8#t=566s) the username and password were provided for the SSH layer, IOS one.

Depending on whether you can ask for all the credentials directly from SSH or if you must in part go through IOS, I should be able to provide a tailored solution.

0

I find this sample here i hope this gives you some direction. Before you run this code certify that you run:
gem install net-ssh

   #!/usr/bin/env ruby
   require 'net/ssh'

   HOST = '192.168.1.113'
   USER = 'username'
   PASS = 'password'

   Net::SSH.start( HOST, USER, :password => PASS ) do|ssh|
   result = ssh.exec!('ls')
   puts result
   end

The only requirement of Net::SSH are openSSL bindings for ruby, you can check if you ok with this:

C:\Sites>ruby -ropenssl -e 'puts OpenSSL::OPENSSL_VERSION'
OpenSSL 1.0.0k 5 Feb 2013

C:\Sites>

EDIT:
I did some research and found some answers, i think you should take a look at:
telnet to a cisco switch and
net-ssh to configure a juniper router

Community
  • 1
  • 1
amalrik maia
  • 478
  • 5
  • 11