Ruby ruby telnet 如何进行 Yes/No 这种条件的判断

chen248283935 · September 04, 2013 · 2000 hits

Login authentication

(Username|Password):

如上,Username 的地方可能是 Username,也有可能直接是 Password 原来想用一个正则表达式,然后使用 waitfor 进行匹配,如下图

reg_input = /(user(.*?):|id)|(password|mima|login:)/i
telnet = Net::Telnet::new("Host" => ip,   "Timeout" => 10, "Port" => port )
input = telnet.waitfor(reg_input) { | tip |
     information = tip 
}   

然后使用$1,$2看是否匹配,来选择不同的分支。 发现匹配中$1,$2都为 nil,应该如何区分 telnet 中出现的不同情况呢?

No Reply at the moment.
You need to Sign in before reply, if you don't have an account, please Sign up first.