socat: You want it? socat’s got it

Back when I mentioned netcat, I said that no matter what I wrote, I’d be underemphasizing how useful and powerful it was.

The same holds true for socat, which is probably more flexible and more detailed than netcat, if such a thing is believable. Like netcat it’s primarily a network piping tool, but just a skim through the man page tells you it’s taken the idea to a different level. 😯

I could claim some experience with netcat, but socat was new to me until today. But here’s what I collected from around the Web, in terms of fun things to do with it:

Create a virtual network interface:

socat -d -d tun:10.0.0.1/8 tun:192.168.0.1/24

Not that I’m short on network interfaces, but that’s a pretty cool stunt. Thanks go to JustChecking for mentioning that one.

socat can also pull in or redirect data delivered from other programs, which makes it useful in other ways.

date | socat - GOPEN:/tmp/capture,append

And of course, if you take a peek in /tmp/capture now, you’ll see the date listed. Not a huge leap forward for mankind, but has potential if you think about it. Thanks to linux.com for that one, and for this one — creating a virtual private network over ssh:

socat -d -d  \
    TUN:192.168.32.2/24,up \
    SYSTEM:"ssh root@server socat -d -d  - 'TUN:192.168.32.1/24,up'"

I have to admit, that’s clever. One more here, this time from My Stuff:

socat UNIX-LISTEN:/tmp/.X11-unix/X1,fork \
SOCKS4:host.victim.org:127.0.0.1:6000,socksuser=nobody,sourceport=20

Supposedly this attaches itself to the Unix socket created in an X window session, and redirects to an external site. I admit this one I didn’t try, and since the My Stuff page dates back to 2008, it’s possible this doesn’t work like described. An interesting idea though, and lots more on that page.

It’s possible to create software that is so flexible and precise that it is both amazing and bewildering at the same time. socat is proof of that.

3 thoughts on “socat: You want it? socat’s got it

  1. Pingback: ngincat: Four lines of bash, plus netcat | Inconsolation

  2. Pingback: ngincat: Four lines of bash, plus netcat | Linux Admins

  3. Pingback: Bonus: A dozen more remainders | Inconsolation

Comments are closed.