【问题标题】:Ruby and telnet waiting for more dataRuby 和 telnet 等待更多数据
【发布时间】:2018-05-15 18:17:46
【问题描述】:

我正在尝试使用 ruby​​ 脚本登录以登录到我的 telnet apc。

代码:

server = Net::Telnet.new("Host" => "192.168.178.240", 'Timeout' => 10, "Output_log" => "output_log", "binmode" => true ,'Waittime' => 2, "telnetmode" => true )
server.cmd('apc')
server.waitfor((/:.*>|More\?/))
print a

我收到以下错误:我

irb(main):025:0> Device.reboot
Net::ReadTimeout: timed out while waiting for more data
  from app/models/device.rb:15:in `reboot'
  from (irb):25
irb(main):026:0> 

server.match(/([User+Name])\w+) { |str| puts str }
server.waitfor('password') { |str| puts str }

更多日志文件,命令卡在密码字段上。

User Name : apc
Password  : Trying 192.168.178.240...
Connected to 192.168.178.240.

User Name : apc
Password  : 

【问题讨论】:

  • 我认为这些类型的 PDU 设备也支持 SSH,这样就不会那么混乱了。

标签: ruby-on-rails ruby telnet


【解决方案1】:

注意我以前从未使用过这个库,但它对你有什么作用

login_info = {"Name" => "Your User name",
              "Password" => "Your password",
              "LoginPrompt" => /User\sName\s*:/
             }
server = Net::Telnet.new("Host" => "192.168.178.240", 'Timeout' => 10, "Output_log" => "output_log", "binmode" => true ,'Waittime' => 2)
server.login(login_info) { |c| print c } # print the output from the login attempt
server.cmd("String" => 'apc', "Match" => /:.*>|More\?/) do |a|
  print a # print the output as it is read in
end

这应该可以让你通过你现在失败的密码提示部分,但我不知道你还有什么其他意图

【讨论】:

    猜你喜欢
    • 2016-11-24
    • 2013-08-26
    • 2016-12-19
    • 1970-01-01
    • 2010-12-17
    • 2011-07-09
    • 2016-10-30
    • 2015-02-04
    • 1970-01-01
    相关资源
    最近更新 更多