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:
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.