6 ms·
I never realized how useful netcat is
- deleted 17y ago[deleted]
- stse 17y agoI recommend the even more capable Ncat (http://nmap.org/ncat/ http://nmap.org/ncat/), which is a reimplementation of netcat by "The Nmap Project".
- kree10 17y agoI recommend checking out socat (http://www.dest-unreach.org/socat/ http://www.dest-unreach.org/socat/) as well.
- rman666 17y agoI recommend checking out lolcat, too (http://en.wikipedia.org/wiki/Lolcat http://en.wikipedia.org/wiki/Lolcat).
- christopherolah 17y agoI actually thought you were recommending a piece of software that had a punny name...
- jwecker 17y agohttp://nmap.org/ncat/guide/ncat-tricks.html http://nmap.org/ncat/guide/ncat-tricks.html Edit: http://www.dest-unreach.org/socat/doc/socat.html#EXAMPLES http://www.dest-unreach.org/socat/doc/socat.html#EXAMPLES
- moe 17y agoThen just wait until you discover ngrep! ;-)
- yan 17y agonetcat + ssh's -R and -L = unstoppable ssh -D is also awesome for when you need a quick http tunnel. Another trick I picked up is basically: nc -l [port] | named_pipe | nc [other_host] [port] That will tunnel things between two netcat instances, effectively setting up a tunnel. Replace 'named_pipe' with a shell and you have a quick and dirty remote shell.
- boundlessdreamz 17y agoCan you explain this further. There are three machines A,B,C A can connect to B and B can connect to C but A cannot connect to C How can netcat/ssh be used to forward a port on B such that when A connects to that it connects to C [on a specific port]. basically B acts as a proxy.
- yan 17y agoThis is from memory so take it with a grain of salt: 2048 is the port you're forwarding. Machine B: machine_b$ mkfifo /tmp/tunn machine_b$ nc -k -l 2048 < /tmp/tunn | nc [machine_c] 2048 > /tmp/tunn & You should now have a working tunnel. Everything sent to B on 2048 will be sent to C:2048
- ilyak 17y agoIn most of those examples, you'd use telnet or scp or nmap.
- thwarted 17y agonmap is a little heavyweight at times, it's the swiss army knife, while netcat is more like a simple blade. Sometimes it's meaningful to avoid telnet because of the terminal negotiation it does. Other times, telnet is useful because it can do line buffered input, allowing line edits (I often mistype the protocol version string when testing HTTP directly).
- njharman 17y agoyes that is the point. power == doing what would take 3 other programs to do.
- ilyak 17y ago, poorly.
- igrekel 17y agoNot sure if I should share this, but here it goes. One nice trick I used a lot when in college is that some postscript network printers would print raw postscript sent to them on a specific port (which I can't remember sorry). This allowed me to use netcat toprint my documents bypassing the college's print quota system and everyone who would be waiting in the queue.
- cnvogel 17y agoUsually it's port 9100. Bash (and for sure also tcsh or zsh, not to start any flamewar) has a nice builtin tcp-socket interface by redirecting to the "pseudo" tcp device, so you don't even need nc for it on most current unices. cat file.ps >/dev/tcp/10.2.3.4/9100
- yan 17y agoWow, I had no idea about the bash device. This is great.
- dfranke 17y agoNote that it's disabled in Debian because the package maintainer has some stupid notion that it's a security hole.
- blasdel 17y agoWhich is epically obnoxious when you have an open shell on a dying remote box that's lost /lib/libc.so.6 and you're scrounging for a way to restore it. I was halfway through writing a uudecode implementation using only bash builtins when the hosting company got me a serial line on the box. I despise their policy of diddling with every upstream package -- disabling default build options, removing config files, separating the peas from the carrots, splitting pieces off into new packages, and all that anal-retentive bullshit. It's much worse on systems where there are fewer people keeping an eye on the maintainers -- ever try to use fink?
- 17y ago
- sharjeel 17y agoNC allows good quick hacks but beware that it could open security issues as well. e.g. never do "nc -l -p 1234 -e /bin/bash" beyond your local machines.
- durana 17y agoOne of my favorites for quickly copying a directory between hosts is... dsthost# nc -l 1234 | tar -xvzf - -C . srchost# tar -xzf - . | nc dsthost 1234
- pmjordan 17y agoI like using netcat together with dd for cloning hard disks or volumes over a network. Great for cloning laptops, especially out and about, where it's often nontrivial to attach both drives to the same system simultaneously. Inserting gzip/gunzip into the pipe helps over slow connections.
- tlrobinson 17y agoIndeed. I threw together this dead simple HTTP server written in shell + netcat the other day, for debugging some CGI scripts: http://github.com/tlrobinson/wwwoosh/blob/master/wwwoosh.sh http://github.com/tlrobinson/wwwoosh/blob/master/wwwoosh.sh (only handles CGI scripts at the moment, could be modified to serve files, etc)
- almost 17y agoNice, that's really cool :)
- sh1mmer 17y agoI discovered some awesome in Netcat while playing with BashReduce (http://github.com/erikfrey/bashreduce/ http://github.com/erikfrey/bashreduce/). That said BashReduce uses the Debian version of Netcat which is different from every other version I could find. I ended up running Debian in VMWare to get BashReduce up and running on my Mac.
- branden 17y agoLast.fm has a pretty nifty notification system that uses netcat and an IRC bot. http://www.metabrew.com/article/how-we-use-irc-at-lastfm/ http://www.metabrew.com/article/how-we-use-irc-at-lastfm/