Posted By

wupher on 01/14/11


Tagged

textmate ruby telnet


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

thastyle


telnet device


 / Published in: Other
 

  1. def tel_hw_device(commands, options)
  2. return nil if commands.nil? or commands.empty? or options.nil? or options.empty?
  3. cmd_result = {}
  4. telnet = Net::Telnet.new("Host" => options['host'], "Port" => options['port'], 'Prompt' => Regexp.new(options['prompt']), "Output_log" => "output.log")
  5. telnet.cmd("n")
  6. telnet.cmd('root')
  7. telnet.cmd('mduadmin')
  8. telnet.cmd('enable')
  9.  
  10.  
  11. commands.each do |cmd|
  12. # telnet.cmd("String" => cmd,"Match" => /(w+:s+)/){|result| cmd_result[cmd] = result}
  13. telnet.cmd(cmd){ |result| cmd_result[cmd] = result }
  14. end
  15. telnet.close
  16. cmd_result
  17. end

Report this snippet  

You need to login to post a comment.