--Boundary-00 N3DGl+5PS/LhCP
Content-Type: Multipart/Mixed;
boundaryoundary-00 N3DGl+5PS/LhCP"
--Boundary-00 N3DGl+5PS/LhCP
Content-Type: text/plain;
charset so-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
I don't know perl's cisco library, but this (see attached) is what I wrote to
send commands to cisco routers and switches or fetch some values.
To get it's running config for example I do this:
------------------------------------
require 'ciscotelnet'
c iscoTelnet.new("Host" '10.253.1.8',
"Password" "users-password",
"Enable" "enable-password",
"User" "martin")
c.open
c.login
c.enable
c.cmd "terminal length 0"
puts c.cmd("show run", 20)
------------------------------------
Martin
On Saturday 31 March 2007 13:40:15 Robert Dober wrote:
> On 3/31/07, Brian Candler <B.Candler / pobox.com> wrote:
> > On Sat, Mar 31, 2007 at 12:48:22AM +0900, Pablo Zorzoli wrote:
> > > Is there any approach similar to perl's Net:Telnet:Cisco [1] in ruby?
> > > Has anyone nice experiences in this mix?
> >
> > Not that I'm aware of. But if you discover something please let me know -
> > I'm going to have to do this myself in the next few weeks too.
> >
> > I was planning just to use plain Net::Telnet, which I think is good
> > enough for what I need.
>
> Please kindly let me know about this, I was trying to do this with
> Catalyst 29xx series Switches and a 2600 router, no luck so far, I
> guess the prompt, timeout selection is quite tricky :(
>
> Cheers
> Robert
>
> >I was also planning to try to make a wrapper for Net::SSH
> > to make it provide an IO object that can be passed into Net::Telnet.
> >
> > Regards,
> >
> > Brian.
--Boundary-00 N3DGl+5PS/LhCP
Content-Type: application/x-ruby;
name
iscotelnet.rb"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename
iscotelnet.rb"
require 'net/telnet'
class CiscoTelnet
require 'net/telnet'
def initialize options
@host ptions["Host"] || "localhost"
@user ptions["User"] || "martin"
@password ptions["Password"] || "nopass"
@enable ptions["Enable"] || "nopass"
@debug ptions["Debug"] || false
@prompt il
end
def debug_out(msg)
$stdout.puts ">> " + msg if @debug
end
def debug_in(msg)
$stdout.puts "<< " + msg if @debug
end
def open
@socket et::Telnet.new("Host" @host)
end
def close
@socket.close
end
# returns last line received
def expect(str)
ret socket.waitfor("String" str, "Timeout" 10) { |rv| debug_in(rv) }
return ret.split('\n').last.strip
end
# overwrite to match dynamic prompt
def cmd(command, timeout)
debug_out command
return @socket.cmd("String" command, "Match" Regexp.new(Regexp.escape(@prompt)), "Timeout" timeout) { |c| debug_in(c) }
end
def print(s)
@socket.print(s) { |c| debug_out c }
end
def puts(s)
@socket.puts(s) { |c| debug_out c }
end
def login
expect "Username"
puts @user
expect "Password"
puts @password
@prompt xpect '>'
$stdout.puts "prompt is " + @prompt if @debug
end
def enable
puts "enable"
expect "Password"
puts @enable
@prompt xpect '#'
$stdout.puts "new prompt is " + @prompt if @debug
end
end
--Boundary-00 N3DGl+5PS/LhCP--
--Boundary-00 N3DGl+5PS/LhCP--