开发者

Problem in using NET/TELNET class in ruby

开发者 https://www.devze.com 2023-02-16 17:54 出处:网络
Hii all, I am telneting a machine using \"net/telnet\" class that comes in ruby but am having some starnge problem...This is below code i have

Hii all, I am telneting a machine using "net/telnet" class that comes in ruby but am having some starnge problem...This is below code i have

require 'net/telnet'
ip="192.168.247.111"
localhost = Net::Telnet::new("Host" =>ip,
                           "Timeout" => 50,

                       "Prompt" => /[$%#>] \z/n)

localhost.login("root", "root") { |c| print c } 
开发者_运维百科

Now when i run the above code i got en error like

 c:/ruby/lib/ruby/1.8/net/telnet.rb:352:in `initialize': getaddrinfo: no address
 associated with hostname. (SocketError)

But if i harcoded th Ip address like "Host"=> "192.168.247.111"

am able to make it work means able to telnet to machine...but my requirement it to assign from some variable ....How could i achieve it??


Try this:

require 'net/telnet'
ip="192.168.1.5"
localhost = Net::Telnet::new("Host" => "#{ip}", "Timeout" => 50, "Prompt" => /[$%#>] \z/n)
localhost.login("ziad", "ziad") { |c| print c }
0

精彩评论

暂无评论...
验证码 换一张
取 消