Net::Telnet question

N

Nick H.

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 !
 
B

Brian Candler

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
<hit enter>

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top