Using / dev / tcp instead of wget
Why does it work:
exec 3 <> / dev / tcp / www.google.com / 80 echo -e "GET / HTTP / 1.1 \ n \ n"> & 3 cat <& 3
And this failure:
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 this on one line without using wget, curl or any other library?
The second fragment does not work, because it opens two separate TCP sockets. echo connects to www.google.com and records an HTTP request; and then the second line opens another connection and tries to read from this socket. The second socket is simply blocked because Google expects to send an HTTP request.
Not my area of ββexpertise, but I think that the second sample will open the second connection, while the first sample holds an open handle for the same connection. Therefore, any solution that involves opening only one connection should work.