Telnet connection closes before i execute GET command

I tried the below steps for telnet command from a remote server:

  1. telnet myservice.com 443
  2. GET / HTTP/1.0
  3. Press enter key twice

Please see the output below:

   bash-3.2$ hostname 
 remoteserver1 
  bash-3.2$ telnet myservice.com 443 
 Trying 191.172.172.133... 
 Connected to myservice.com. 
 Escape character is '^]'. 
 GET / HTTP/1.0 
 HTTP/1.1 302 Moved Temporarily 
 Server: Oracle-iPlanet-Web-Server/7.0 
 Date: Tue, 17 Jul 2018 14:04:20 GMT 
 Location: https://myservice.com:443/ 
 Content-length: 0 
  Connection to myservice.com closed by foreign host. 
 

But, when I try the telnet command locally [from the same server where https://myservice.com:443/ service is running] it closes the connection even before I could get the response output of the GET command as shown below:

   bash-3.2$ hostname 
 localserver1 
  bash-3.2$ telnet myservice.com 443 
 Trying 191.172.172.133... 
 Connected to myservice.com. 
 Escape character is '^]'. 
 GET / HTTP/1.0 
  Connection to myservice.com closed by foreign host. 
 

So, like you can see above the connection gets closed even before the GET command could return any output.

Please share a fix so that I can fire the GET command before the telnet connection closes.

Isn't transmission to and from a https port encrypted?
Does curl work with https?

Try: openssl s_client -connect myservice.com:443 to do SSL connection.

1 Like

Let me explain further.

  1. How can I input/feed the below three commands "non-interactively" to the telnet command.
a. GET / HTTP/1.0 
b. Enter key
c. Enter Key

telnet+GET works from a remote host so i expect telnet+Get to work locally. I don't wish to use curl or any other tool.

Can you please help ?

if you are doing it locally, then you must either use a local ip address, or add myservice.com to your local dns server so that it resolves to the local ip address.

1 Like

Can anyone please answer the first part of my query posted below

  1. How can I input/feed the below three commands as "non-interactive" to the telnet command.
a. GET / HTTP/1.0 
b. Enter key
c. Enter Key

telnet is interactive. If you don't want interaction, why use it? There's much more appropriate tools.

Answering "why use it" may tell us what you actually need, and by that, an actual solution which may not have been what you expected.

If you absolutely insist on making telnet work interactively you could probably kludge something with expect.

Does the openssl have timeout option for us to specify ?

I m aware of timeout shell command but it does not work on solaris sparc .. it only works on Linux.