Create a single-use TCP proxy with debug output to stderr

socat -v tcp4-l:<port> tcp4:<host>:<port>
or you can add "-x" to get a typical hexdump like output
Sample Output
< 2009/09/25 22:15:54.755594  length=87 from=0 to=86
220 ESMTP Sendmail 8.14.2/8.14.2; Fri, 25 Sep 2009 22:15:54 +0530\r
> 2009/09/25 22:16:02.684058  length=13 from=0 to=12
HELO abcmail
< 2009/09/25 22:16:02.780237  length=91 from=87 to=177
250 Hello [], pleased to meet you\r
> 2009/09/25 22:16:10.336954  length=5 from=13 to=17
< 2009/09/25 22:16:10.403763  length=50 from=178 to=227
221 2.0.0 closing connection\r

By: sitaram
2009-09-25 17:10:16

1 Alternatives + Submit Alt

  • USAGE: gate listening_port host port Creates listening socket and connects to remote device at host:port. It uses pipes for connection between two sockets. Traffic which goes through pipes is wrote to stdout. I use it for debug network scripts.

    gate() { mkfifo /tmp/sock1 /tmp/sock2 &> /dev/null && nc -p $1 -l < /tmp/sock1 | tee /tmp/sock2 & PID=$! && nc $2 $3 < /tmp/sock2 | tee /tmp/sock1; kill -KILL $PID; rm -f /tmp/sock1 /tmp/sock2 ; }
    true · 2009-09-25 08:10:23 1

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: