I need to get the http header response from a server (google) with telnet, as i don't have curl or wget in my busybox environment. Also, I'm behind a proxy. So on the command line I can successfully do this:
$ telnet proxy.ip port
HEAD http://www.google.com/ HTTP/1.1
{hit enter twice}
HTTP/1.1 200 OK
Date: Tue, 15 Jan 2019 09:11:28 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
entire header follows...
But I dont know how to put this into a shell script. This is what I tried:
#!/bin/sh
(
echo "GET http://www.google.com/ HTTP/1.1"
echo
echo
echo "exit"
) | telnet proxy.ip port
But it doesnt give me any output at all.
telnet
will read input from a pipe. Do you havenc
(netcat)? The manpage contains this example:$ echo -n "GET / HTTP/1.0\r\n\r\n" | nc host.example.com 80
nc host.example.com 80
withnc proxy.ip port
in the example from the manpage.