&3 cat <&3" />
开发者

Using /dev/tcp instead of wget

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 echo connects to www.google.com and 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.


Not my area of expertise, but I think that the second sample will open a second connection, while the first sample keeps an open handle to the same connection. So any solution which involves opening only one connection should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜