
Cool stuff you can do with netcat - ma2rten
http://en.wikipedia.org/wiki/Netcat
======
petdog
Poor man's skype:

sender

    
    
        arecord -f cd -c 2 | lame -b128 - - | netcat -u your-ip 6881 | mpg123 -
    

receiver

    
    
       arecord -f cd -c 2 | lame -b128 - - | netcat -u -l 6881 | mpg123 -

~~~
1337p337
I used to do this with a friend in the days when modems tied up phone lines.
You have to pass a much lower number to lame's -b option, though.

------
yan
If you love nc, also check out socat (<http://www.dest-unreach.org/socat/>)

~~~
haldean
Or ncat (<http://nmap.org/ncat/>). My personal favorite useless example is the
persistent webserver:

    
    
        ncat -lkp 8080 --sh-exec 'echo -ne "HTTP/1.0 200 OK\r\n\r\nThe date is "; date;'

------
killbot5000
Don't forget easy ssh host hopping.

ssh -oProxyCommand="ssh host1 nc host2 22" host2

~~~
roadnottaken
Interesting. Thanks for the tip! I'd never heard of ssh host hopping, but have
been doing 2-3 sequential ssh logins for years. I always wondered if this was
possible somehow! I found this nice tutorial that explains your tip in detail:

[http://sshmenu.sourceforge.net/articles/transparent-
mulithop...](http://sshmenu.sourceforge.net/articles/transparent-
mulithop.html)

This made all the time I've spent on HN in the past week worthwhile! :)

~~~
thristian
At $EMPLOYER, I have a script that takes a description of the network
topology, converts it to a sequence of Host stanzas and writes them to
~/.ssh/config. The source file is simple enough that the sysad team can keep
it up-to-date when they change the network configuration, and most people just
have to run the 'update' script occasionally to have Super SSH Powers. It's
quite popular.

~~~
roadnottaken
Don't suppose you'd be willing to post this uber-script somewhere?

~~~
thristian
Unfortunately it's not really self-contained enough to post; the most
complicated thing in it is basically a copy/paste of the "Dijkstra's
Algorithm" sample-code on Wikipedia, though.

------
roadnottaken
Anyone want to give a few examples of cool things they _actually_ do with
netcat?

~~~
yan
I use it for:

\- creating quick and dirty proxies (nc > fifo > nc). (edit: you can also
bridge udp->tcp this way, which makes proxying UDP through an ssh tunnel
possible)

\- making simple GET requests (printf "GET / HTTP/1.0\r\nHost: www\r\n\r\n" |
nc host 80, or save the full request and pipe that to netcat)

\- checking if a port is open (nc -p 8080 host, tends to be quicker than nmap
and less to type)

\- dumb file transfers ('nc -l port > file' on one machine, 'file | nc host2
port') on another (or using tar for directories). Usually I use ssh/scp, but
sometimes that nc trick works just fine..

------
cosgroveb
I actually got in trouble trying to use netcat for something quite legitimate
in my former job at RandomBigCorp... Oops.

~~~
Tuna-Fish
Please elaborate?

At my current place of employment, "hacking tools" are banned. On that list is
netcat. It is installed on every unix desktop and server, and I use it daily.
I have decided to just not point out the stupidity of this -- they might do
something that's even more stupid as a response.

~~~
roqetman
I've always found that it's better to ask for forgiveness than permission in a
large bureaucratic technically simplified corporation, otherwise I'd get
nothing done. Ask, and they say "no".

~~~
js2
It's always wise to exercise discretion: <http://db.tidbits.com/article/8886>

Yes, that Randall Schwartz.

~~~
silentbicycle
It's too bad you can't expunge lawyers' fees. Yikes.

And no blame, but it's probably a good idea to say, "We're scanning for weak
passwords" first. The sysadmin at the library I used to work at ran password
crackers occasionally, and sent out an e-mail once saying that he suddenly
knew a lot of staffs' boyfriends names. It's a delicate issue.

------
jeffDef
If you add the live_console gem to a rails app, you can use netcat to run IRB
against the live application. You can change the app's state from a console,
like flushing a cache or even making a patch, without having to restart the
app.

