I connected an SNMP monitoring system using two socats and an ssh tunnel. One socat to forward UDP over TCP to the locally encrypted port, and another to take it off on the other side and forward it to a local SNMP listener. It was a for a control system we were building that could monitor temperatures and control fan speeds in a computer cooling system. We ran it across several states in the US, and it was just to get an early demo of how the system would work before hardware was more locally available and the damned thing worked...
This made a lot of people very happy and it was really crazy to be on the phone with the other folks and have them rev up the fans in our lab via SNMP through this channel.
seriously, I was introduced to socat about 5 months ago... blew my mind. netcat is good and I still use it to quickly send custom GET requests, but socat is like a swiss-army knife containing many swiss-army knives. It even forwards unix-domain sockets and doesn't necessarily need root permissions like iptables.
Agreed. If netcat is the swiss-army knife of network tools, socat is the complete utility belt. I discovered socat because netcat simply wouldn't bend in all the ways I needed it to. There is NOTHING ad-hoc network related that I haven't been able to perform with socat.
No better way to get the absolute maximum possible use of your pipe with the absolute minimum amount of security! Netcat has saved my butt when that 12GB package absolutely, positively has to be there within the next minute.
One of the coolest network utilities around. It's literally like a cat piped through the network. These are all great examples.
From the site: '"ncp" is a utility for copying files in a LAN. It has absolutely no security or integrity checking, no throttling, no features, except one: you don't have to type the coordinates of your peer.'
Sweet :) I wasn't doing it over lan though, totally different subnets here. It's easy to quickly open the port I want to use for netcat on a remote machine and copy files quickly that way.
If you're interested in completely saturating all your resources for the maximum possible transfer speed, check out Tsunami: http://tsunami-udp.sourceforge.net/ -- It's a UDP protocol designed for raw throughput. Also no security or checking, but it does support throttling which is nice. I've tested and it actually does exceed netcat's rate by a few percent, but it's a little less reliable (client and server have to agree on a lot of things). Pretty cool to experiment with though :)
As an alternative to all of the above, consider UDPCast. It's point is that it can multicast; but it is also great for point-to-point copies. I adds its own reliability layer, so don't be scared of UDP in the name. It can rate limit, if you want. I've used it to great effect to shuffle a lot of GB to a bunch of servers at the time.
Way down at a low level, the network hardware/firmware knows how to send data 1:N. Using that is a single easy command away, but hardly anyone knows it.
I like it (tar|nc) as a quick alternative when moving data to or from low performance devices such as Android phones. Rsync/SSH really burns a lot of power for encryption. Makes a full x GB Backup much faster to pipe it through netcat (or bashs /dev/tcp if available).
Also +1 for socat as a netcat replacement, having SSL there when needed is really helpful. I use it a lot for testing when developing network applications, replacing one end point with a fixed set of responses or even typing stuff in interactively etc.
I really don't see how Apache vs Nginx will give you that much performance increase. The majority of the processing time for a request is in the backend (rendering, compiling, db calls, &c). Improved caching would give much better performance gains than just switching a server without any other improvements.
Compare memory usage; also Apache has problems with many concurrent connections and low hard limits as default, which nginx handles much better. Varnish of course would also be a valid improvement.
I used to think this too, but I recently switched a PHP app I run over to Nginx from Apache, nginx uses much less memory, and consequently the app can run on far less instances, it's been a huge win.
This app has many long-running connections and a write-heavy workload, your mileage may vary.
On Plan 9, where networked I/O is done through a file system, there is no need for netcat, you can use regular Plan 9 tools to do anything netcat does and more.
nc is ancient but flexible. want encryption? pipe in openssl's command line to encrypt a stream. i'm pleased to see it so widely deployed.
for fun, find the original hobbit nc source code and read the comments. the complaints in there about writing a portable utility and dealing with platforms' weirdness and brokenness.
It should be noted that rlwrap works on all programs that use readline. I've used it when starting out with programming in SML and getting annoyed at the missing arrow-up command history.
Actually, rlwrap works well with all line-reading programs that DON'T use the readline library, and not so well with some that do. Like the python debugger. :(
Actually the netcat shipped on most/all common Linux distributions (though IIRC, frustratingly not Cygwin which has a more limited one without the SOCKS features) is the one from OpenBSD.
But obviously the article was written from the perspective of "Fun commands available on Linux". I'm all for giving proper credit where it is due, but it's asking a little too much to expect that every newbie tutorial is going to inflict a full software genealogy on the poor reader...
In the situations where nc is useful then scapy is probably not an option. Nc, dd, and a few others are almost always present and great when you are in a real bind... something went wrong in a network install in pxelinux, and you want to copy off dumps or config files, or copy on a missing file. Otherwise, there are better ways to do most of the things mentioned in the article, most involving scp.
EDIT: the number of responses to this article happily highlighting the lack of security in netcat just terrifies me.
EDIT2: Ah, I see what you were saying (and scapy is an awfully cool library). It was just a convenient place for me to highlight was I didn't think was highlighted enough in the article: nc can do neat things, but not much that can't be accomplished better with other tools - its big advantage is that it's almost always present, even if ssh/scp, rsync, netstat, wget/curl, etc are not. Like using cat + sed as a text editor :)
I know they are different tools, I meant if you like to play with ncat, tcpdump etc and/or you're learning netsec you may want to play with scapy. Directed to the very few readers that may know about nc and not scapy :-)
It seems there are better alternatives to netcat, i.e. socat and ncat. Why should I choose either? I'd like to learn how to use such a tool, but I'm not a CS major.
For the simple task of moving bytes through a tcp connection (what the article is about) netcat will be fine.
Socat allows you to use raw interfaces, or fifos, SSL, proxies, serial ports,... as one or both end points. E.g. you can forward arbitrary tcp connections (tcp relay;) but also connect stdin/stdout if a program to a serial port... just very, very, very versatile.
Few months earlier, when I was learning shell programming, I created a simple file transfer script using netcat (nc) and zenity (for little GUI).. Can be used to transfer files inside LAN.. It was actually made to use inside our college lab for my non technical friends..
I can't seem to get the chat example to work on OS X. Does anyone know if it's limited to working on Linux?
[Edit] I was using nc 127.0.0.1 so I'm not sure if netcat can't communicate with lo. Also tried SSHing into a Linux box I own, now I get "Connection refused" on the client side (OS X).