Net::Telnet question

I am trying to use Net::Telnet to telnet to a website to check network
connectivity…

On linux prompt i get the following output:

$ telnet to abc.xyz.com 443
Trying xxx.xxx.xxx.xxx…
Connected to abc.xyz.com.
Escape character is ‘^]’.
hello world
Connection closed by foreign host.

When I type in “hello world” string it responds with “Connection closed
by foreign host.” which is what is expected and I need to check with
telnet. In the script, I need to put a error checking code which detect
if the port is blocked and it should timeout. How can I use Net::Telnet
to put the string “hello world” in order to get appropriate response or
timeout on hangs.
Here is my code:


#!/usr/bin/env ruby

require ‘net/telnet’

host = Net::Telnet::new(
“Host” => " abc.xyz.com",
“Port” => 443,
“Telnetmode” => false,
“Output_log” => “telnet.log”,
“Dump_log” => “dump_log.log”
)

lines = “Hello World !!!”

host.puts(lines)

host.waitfor(/./)do |data|
puts data
end

All the response I get from this script is “nil”

Can someone help me with this !

Nick H. wrote in post #979220:

I am trying to use Net::Telnet to telnet to a website to check network
connectivity…

That’s the wrong tool for the job. If you just want to test that the
remote end accepts a TCP connection, use a socket:

require ‘socket’
TCPSocket.open(“abc.xyz.com”, 443)

And this is all nicely wrapped up for you, complete with configurable
timeout, in ping.rb in the standard ruby library (this may be somewhere
like /usr/lib/ruby/1.8/ping.rb on your system)

Read the file itself for examples how to use it.

On linux prompt i get the following output:

$ telnet to abc.xyz.com 443
Trying xxx.xxx.xxx.xxx…
Connected to abc.xyz.com.
Escape character is ‘^]’.
hello world
Connection closed by foreign host.

That’s because (1) you are typing something which is not valid HTTP, and
so the server disconnects immediately, and (2) you are connecting to a
HTTPS server (port 443), so it needs to talk SSL.

A valid test would be:

openssl s_client -connect abc.xyz.com:443
GET / HTTP/1.0
Host: abc.xyz.com

But if you just want to check if the host is there, not whether SSL or
HTTP are working, then ping.rb is what you want.

Regards,

Brian.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs