
Netcat – The swiss army knife of networking - giis
http://mylinuxbook.com/linux-netcat-command/
======
kaeso
I couldn't really survive without socat: <http://www.dest-
unreach.org/socat/doc/socat.html#EXAMPLES>

~~~
dleimbach
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.

------
calinet6
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.

~~~
c-oreills
If that's your use case then have a look at ncp: <http://www.fefe.de/ncp/>

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.'

~~~
calinet6
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 :)

~~~
kylecordes
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.

[http://kylecordes.com/2008/multicast-your-db-backups-with-
ud...](http://kylecordes.com/2008/multicast-your-db-backups-with-udpcast)

------
c-oreills
See also ncat - netcat for the 21st century: <http://nmap.org/ncat/>

~~~
peterwwillis
This is what everyone should be using instead of 'nc'. SSL, SCTP, IPv6,
proxying, hex dump, keep open, waits, and more.

I wouldn't call 'socat' a swiss army knife. More like a tool shed. But it is
very handy at times.

------
stiff
Ngrep is another awesome tool that is a networking equivalent of a common UNIX
utility (although a more loose one in this case):

<http://ngrep.sourceforge.net/>

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.

------
thomaslutz
Nginx - the swiss army knife to avoid webserver overloading after getting
frontpaged on HN (currently seeing error 500 from Apache only).

~~~
jimktrains2
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.

~~~
thomaslutz
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.

~~~
nisa
Apache can fill your 100Mbit line just fine for most cases. It's Wordpress
where 98% of your processing time is spend.

Switching to nginx does not help at all in most cases. I really like nginx but
Apache gets a lot of unfounded hate.

------
matugm
I love socat, way more powerful than netcat, it also supports SSL and IPv6, I
wrote about some netcat to socat examples here
<http://www.blackbytes.info/2012/07/socat-cheatsheet/>

~~~
est
and it supports sctp.

------
pjmlp
Except it is not Linux specific, rather a UNIX born utility.

------
4ad
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.

I miss this dearly on Unix.

~~~
coolsunglasses
There are two kinds of operating systems, those that people use and those that
people don't complain about.

------
sigil
Network REPL, with autocomplete and history:

    
    
        rlwrap nc ....

~~~
runejuhl
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.

~~~
sigil
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.
:(

~~~
runejuhl
Hm. You're right. Next time I'll read a bit further in the man page.

------
gtrubetskoy
Why is it a _Linux_ netcat command? What about the FreeBSD netcat or the
Solaris one?

~~~
ajross
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...

------
jnazario
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.

------
sliverstorm
My favorite use of nc to date:

cat disk.img > nc

nc > /dev/sda

~~~
NegativeK
This is basically #7, and I found it particularly handy when Ghost barfed on
my source image.

Since we had an entire lab to clone to, we combined dd, netcat, and tee to
just daisy chain the data out. It worked _magically_.

~~~
Jtsummers
That was exactly my experience, and I nearly wrote the same thing. Frustrating
day saved by 2 simple commands.

------
fduran
Just in case: if you like ncat and networking tools check out also scapy
<http://www.secdev.org/projects/scapy/demo.html>

~~~
3am
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 :)

~~~
fduran
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 :-)

------
chm
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.

~~~
cnvogel
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.

<http://www.dest-unreach.org/socat/doc/socat.html>

~~~
chm
Thank you.

------
amenghra
make sure you checkout socat. It's netcat on steroids (<http://www.dest-
unreach.org/socat/>)

------
zyberkiddy
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..

<https://github.com/zyberkiddy/netcat-file-transfer>

------
ancarda
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).

[Edit Again] UDP works fine!

    
    
        Server: nc -ul -p <Port>
        Client: nc -u <IP> <Port>

------
vinhboy
This really cool. I have always wondered if there was tool to quickly open a
chat between two computers. It's nice to learn about this.

------
NoodleIncident
Site's down. Didn't know that HN hugged so hard...

~~~
mhb
Plenty of other previous mentions here for you to peruse:
[https://www.hnsearch.com/search#request/submissions&q=ne...](https://www.hnsearch.com/search#request/submissions&q=netcat&start=0)

