Problem with ruby telnet really need help now plz

i have been using ruby telnet class to run a dump in a northtel switch
and capture it to a file.
here is the error .
Renameing GSMFILES

Download GPRS

Download BSVC

Download SSOP

An established connection was aborted by the software in your host
machine.

c:/ruby/lib/ruby/1.8/net/telnet.rb:601:in `syswrite’: An established
connection was aborted by the software in your host machine.
(Errno::ECONNABORTED)

    from c:/ruby/lib/ruby/1.8/net/telnet.rb:601:in `write'

    from c:/ruby/lib/ruby/1.8/net/telnet.rb:625:in `print'

    from c:/ruby/lib/ruby/1.8/net/telnet.rb:634:in `puts'

    from C:\Documents and

Settings\rhunte\Desktop\telnetmonster\lib/telnet.rb:30:in `telnet’

    from C:/Documents and

Settings/rhunte/Desktop/telnetmonster/lib/main.rb:63

and here the class code:

require “rubygems”
require “net/telnet”
#================================

class Telnet
attr_accessor :host , :user ,:pass , :cmd ,:cmd2 ,:cmd3,:outfile,:ex

def initialize

end

def telnet
begin
t = Net::Telnet::new( “Host” => @host,“Timeout” => 200000,
“Telnetmode”=> true,“Waittime”=>2000)
t.puts @user
t.puts @pass
t.puts @cmd
t.puts @cmd2
t.puts @cmd3
t.puts(“logout”)
File.open(@outfile,“w”)
t.cmd("") do |data| print data
File.open(@outfile, “a”) { |i|
i.print(data)
}
end
rescue StandardError => @ex
puts @ex
end
ensure
t.puts(“logout”)
end

end

Well, ECONNABORTED is unusual, and is probably some sort of firewalling
problem. What happens if you are on the same machine as your Ruby
program and telnet to the same target host?

Try running

tcpdump -i eth0 -n -s0 -X host x.x.x.x

to look at the traffic to/from host x.x.x.x. (Or Wireshark if this is a
Windows box).

I can see a few other problems.

  t = Net::Telnet::new( "Host" => @host,"Timeout" => 200000,

“Telnetmode”=> true,“Waittime”=>2000)

These timeouts are in seconds, not milliseconds

  t.puts @user
  t.puts @pass
  t.puts @cmd
  t.puts @cmd2
  t.puts @cmd3
  t.puts("logout")

You are blasting all these strings to the device, without waiting for
prompts first.

If t.login doesn’t work for you, do it by hand:

log = lambda { |c| STDERR.print c }

t.waitfor(/ogin:/, &log)
t.puts @user
t.waitfor(/assword:/, &log)

File.open(@outfile,"w")

Here you open the file, but discard the file handle completely, so it
will be closed again when the garbage collector next runs.

  t.cmd("") do |data| print data
    File.open(@outfile, "a") { |i|
    i.print(data)
    }
  end

This re-opens the outfile for every response or part-response received
from the target device. Much better to open it once, e.g.

log = nil
File.open(@outfile,“a”) do |f|
log = lambda { |c|
STDERR.print c
f.print c
}
end

Another less painful way to get logging is to use the Output_log option,
e.g.

      t = Net::Telnet.new( "Host" => @host, "Output_log" => 

@outfile)

or

      t = Net::Telnet.new( "Host" => @host, "Output_log" => 

“/dev/stderr”)

(but this won’t write to both, of course)

Can you connect normally?

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

Julian L. wrote:

Can you connect normally?

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

yes i can and catpute the file using cross talk.
i am trying to automate that process
here is the modifed code
still faling btw

To change this template, choose Tools | Templates

and open the template in the editor.

require “rubygems”
require “net/telnet”
#================================

class Telnet
attr_accessor :host , :user ,:pass , :cmd ,:cmd2 ,:cmd3,:outfile,:ex

def initialize

end

def telnet
begin
t = Net::Telnet::new( “Host” => @host,“Timeout” => 50000000,
“Telnetmode”=> true,“Waittime”=>2000,“Output_log”=> @outfile)
t.puts @user
t.puts @pass
t.puts @cmd
t.puts @cmd2
t.puts @cmd3
t.puts(“logout”)
f = File.open(@outfile, “w”)
t.cmd(“”)
t.write(“bottom”)
f.close
end

rescue StandardError => @ex
puts @ex
ensure

t.puts("logout")

end
end

the error message
An established connection was aborted by the software in your host
machine.

c:/ruby/lib/ruby/1.8/net/telnet.rb:601:in `syswrite’: An established
connection was aborted by the software in your host machine.
(Errno::ECONNABORTED)

    from c:/ruby/lib/ruby/1.8/net/telnet.rb:601:in `write'

    from c:/ruby/lib/ruby/1.8/net/telnet.rb:625:in `print'

    from c:/ruby/lib/ruby/1.8/net/telnet.rb:634:in `puts'

    from C:\Documents and 

Settings\rhunte\Desktop\telnetmonster\lib/telnet.rb:34:in `telnet’

    from C:/Documents and 

Settings/rhunte/Desktop/telnetmonster/lib/main.rb:51

Rayon Hunte wrote:

Julian L. wrote:

Can you connect normally?

Blog: http://random8.zenunit.com/
Learn rails: http://sensei.zenunit.com/

yes i can and catpute the file using cross talk.
i am trying to automate that process
here is the modifed code
still faling btw

To change this template, choose Tools | Templates

and open the template in the editor.

require “rubygems”
require “net/telnet”
#================================

class Telnet
attr_accessor :host , :user ,:pass , :cmd ,:cmd2 ,:cmd3,:outfile,:ex

def initialize

end

def telnet
begin
t = Net::Telnet::new( “Host” => @host,“Timeout” => 50000000,
“Telnetmode”=> true,“Waittime”=>2000,“Output_log”=> @outfile)
t.puts @user
t.puts @pass
t.puts @cmd
t.puts @cmd2
t.puts @cmd3
t.puts(“logout”)
f = File.open(@outfile, “w”)
t.cmd(“”)
t.write(“bottom”)
f.close
end

rescue StandardError => @ex
puts @ex
ensure

t.puts("logout")

end
end

the error message
An established connection was aborted by the software in your host
machine.

c:/ruby/lib/ruby/1.8/net/telnet.rb:601:in `syswrite’: An established
connection was aborted by the software in your host machine.
(Errno::ECONNABORTED)

    from c:/ruby/lib/ruby/1.8/net/telnet.rb:601:in `write'

    from c:/ruby/lib/ruby/1.8/net/telnet.rb:625:in `print'

    from c:/ruby/lib/ruby/1.8/net/telnet.rb:634:in `puts'

    from C:\Documents and 

Settings\rhunte\Desktop\telnetmonster\lib/telnet.rb:34:in `telnet’

    from C:/Documents and 

Settings/rhunte/Desktop/telnetmonster/lib/main.rb:51

i have made some more changes and here it is

To change this template, choose Tools | Templates

and open the template in the editor.

require “rubygems”
require “net/telnet”
#================================

class Telnet
attr_accessor :host , :user ,:pass , :cmd ,:cmd2 ,:cmd3,:outfile,:ex

def initialize

end

def telnet
begin
t = Net::Telnet::new( “Host” => @host,“Timeout” => 200000,
“Telnetmode”=> true,“Waittime”=>2000,“Output_log” => @outfile)
t.puts @user
t.puts @pass
t.puts @cmd
t.puts @cmd2
t.puts @cmd3
t.puts(“logout”)

File.open(@outfile,“w”)

t.cmd("")

end
rescue StandardError => @ex
puts @ex

ensure
t.puts(“logout”)
end

end

i am now using the telnet output_log to write the files bu i am still
getting the error it runs for about a hour or so and then comes up with
the error and not always that the same place. it’s freaking me out

Rayon Hunte wrote:

def telnet
begin
t = Net::Telnet::new( “Host” => @host,“Timeout” => 50000000,
“Telnetmode”=> true,“Waittime”=>2000,“Output_log”=> @outfile)
t.puts @user
t.puts @pass
t.puts @cmd
t.puts @cmd2
t.puts @cmd3
t.puts(“logout”)
f = File.open(@outfile, “w”)
t.cmd("")
t.write(“bottom”)
f.close
end

You’re still not doing this right. You’re blatting a load of lines to
the server, in the hope that it will accept them all, and logging out
immediately in the hope that you will capture the data before it logs
out.

If you do it one line at a time - wait for prompt, send line, wait for
prompt, send line etc - then you will be able to find out at which point
it is failing.

Also, try using the Dump_log option. This is like Output_log but it
gives you a raw hex dump of data in both directions.