Why does this work:
exec 3<>/dev/tcp/www.google.com/80 echo -e "GET / HTTP/1.1\n\n">&3 cat <&3
And this fail:
echo -e "GET / HTTP/1.1\n\n" > /dev/tcp/www.google.com/80 cat </dev/tcp/www.google.com/80
Is there a way to do it in one-line w/o using wget, curl, or some other library?
The second snippet fails because it opens two separate TCP sockets. The
echoconnects towww.google.comand writes the HTTP request; and then the second line opens another connection and tries to read from that socket. The second socket simply blocks because Google is waiting for the HTTP request to be sent.