The tool you are looking for is socat
. Since you are testing one single web server, you can ask it to establish a permanent connection to that server (as long as it doesn't choose to close it -- adjust your timeouts accordingly) and once this is done, you can use the connection as a tunnel. Below are two ways to accomplish this.
Querying through a Unix socket
curl
has a --unix-socket
option that allows you to send HTTP requests and receive HTTP replies through a Unix socket (thank you, thrig, for your enlightening comment)
You would use it like this:
socat TCP:10.5.1.1:80 UNIX-LISTEN:/tmp/curl.sock,fork
Then, on another terminal:
curl --unix-socket /tmp/curl.sock http://10.5.1.1/message1.txt
curl --unix-socket /tmp/curl.sock http://10.5.1.1/message2.txt
...
Querying through a pseudo-HTTP-proxy
You can also make your tunnel available as a pseudo-proxy through which wget
, curl
,... would connect. This solution has the advantage to not be limited to curl
.
This time, socat
listens to a local TCP port (say 3128):
socat TCP:10.5.1.1:80 TCP-LISTEN:3128,fork,reuseaddr
Then, on another terminal:
export http_proxy='http://localhost:3128'
curl http://10.5.1.1/message.txt
wget http://10.5.1.1/message.txt
....
Note that since the HTTP client is using a proxy, the HTTP request will be slightly altered and this may not be desirable.
Of course, none of those two solutions are intended to be used with multiple HTTP servers since this is your web-server at the end of the channel that receives all the requests.
Best Answer
You have to use it in redirections:
So:
is the right way to use it.
When you used
/dev/tcp/74.125.225.19/80
in a pipe,bash
attempted to run a command named/dev/tcp/74.125.225.19/80
and reported an error because that file didn't exist.The ability to handle
/dev/tcp/host/port
and/dev/udp/host/port
in redirection was added tobash
in version 2.04.You need to compiled
bash
with--enable-net-redirections
option.