How to file a file in telnet

trying to understand the http and headers that I played with telnet to send requests. so as not to enter everything again and again and again, I thought that I would write a small text file with all the commands I needed.

my file is simple:

GET /somefile.php HTTP/1.1 Host: localhost 

i then try passing it to telnet with io-redirection:

 $ telnet localhost 80 < telnet.txt 

but all the output is obtained

 Trying ::1... Connected to localhost. Escape character is '^]'. Connection closed by foreign host. 

what am I doing wrong?

+7
redirect pipe telnet
source share
3 answers

telnet is not the best tool for this job. Try:

netcat localhost 80 <telnet.txt

btw, if you do not have a tool installed on your computer, you can get it here:

http://netcat.sourceforge.net/

+5
source share

The problem is that you immediately load all the data into the telnet command, without waiting for the output. Once your entire input file has been submitted, it will automatically cause telnet to hang up as the input stream reaches the end (EOF). Telnet can still be in the first millisecond or microsecond, waiting for this to happen to establish a connection to the remote server. What you want to do is send the telnet command, and then wait for it to complete its task, and then wait for the server to respond, then send the next command, etc. And just hang up at the very end, when all the commands you sent are actually processed. To do this, use the "wait" script instead of installing the text file. Waiting is a common tool for doing this job.

+4
source share

I do not know if this is possible with telnet . Have you looked at netcat ?

0
source share

All Articles