News for hackers. Stuff that matters.
Re:A Unix Utility You Should Know About: Netcat (2009) by sargun on Sunday August 04, 2013 @11:35PM (#6158284)
There is a better utility available for folks. Ncat - part of famous the Nmap (5) project. It has more features than netcat that people might find useful - like SCTP, SOCKS, etc..

You can find out more about it: http://nmap.org/ncat/

Re:A Unix Utility You Should Know About: Netcat (2009) by harshreality on Monday August 05, 2013 @03:31AM (#6158855)
There's a better utility available than ncat. It's called socat. It has more features than ncat that people might find useful.

http://www.dest-unreach.org/socat/doc/socat.html#EXAMPLES

Re:A Unix Utility You Should Know About: Netcat (2009) by amboar on Monday August 05, 2013 @05:33AM (#6159167)
Dropped into the comments to mention socat. I use it regularly to debug serial and multicast issues or to lash up network logging for random shell scripts. It's a very valuable addition to the toolbox IMO.

Edit: somehow my phone managed to post this comment three times. I've deleted the others

Re:A Unix Utility You Should Know About: Netcat (2009) by sargun on Monday August 05, 2013 @07:32AM (#6159511)
I really like socat, and use it pretty regularly for interfacing with unix sockets. Ncat, and socat have a divergent featureset though. Some combination of the two yields good results.
Re:A Unix Utility You Should Know About: Netcat (2009) by diminoten on Monday August 05, 2013 @12:23AM (#6158459)
Ncat is also more compassionate regarding command line parameters.

Depending on the nc app you have installed on your machine, params will have to be passed using different flags or in differing orders (someone should post why there are different kinds of netcat, I forget). Ncat accepts either format, and sends you cards on your birthday.

Re:A Unix Utility You Should Know About: Netcat (2009) by adventured on Monday August 05, 2013 @01:15AM (#6158588)
I second that Nmap recommendation.

Also, fping is an excellent ping sweeper if that's all you need (and it's now being updated again).

http://fping.org/

Re:A Unix Utility You Should Know About: Netcat (2009) by ams6110 on Sunday August 04, 2013 @11:45PM (#6158310)
You should also know about the so-called "netcat mode" in OpenSSH:

   -W host:port
       Requests that standard input and output on the client be
       forwarded to host on port over the secure channel.  Implies -N,
       -T, ExitOnForwardFailure and ClearAllForwardings.  Works with
       Protocol version 2 only.
Re:A Unix Utility You Should Know About: Netcat (2009) by jwilliams on Monday August 05, 2013 @01:11AM (#6158583)
I only discovered this recently - I was using a literal "nc %h %p" rather than this shortcut.

Also worth noting this is also extremely useful when used in your ~/.ssh/config file.

Re:A Unix Utility You Should Know About: Netcat (2009) by voltagex_ on Monday August 05, 2013 @08:11AM (#6159626)
Can you give an example of how you'd use it in your config?
Re:A Unix Utility You Should Know About: Netcat (2009) by jwilliams on Tuesday August 06, 2013 @01:09AM (#6164919)
Sure. I have something like:

  Host <bastion>
    Hostname <bastion>
    User gateway
    ForwardAgent yes

  Host 10.0.*
    User <username>
    ProxyCommand ssh -W %h:%p <bastion>
Where bastion is the NAT/Bastion SSH host for my infrastructure. 10.0.* are internal IP addresses, which don't work on my network, but get passed through to the bastion (where they do work). Pretty handy as I can just "ssh <internal address>"
Re:A Unix Utility You Should Know About: Netcat (2009) by voltagex_ on Wednesday August 07, 2013 @01:56AM (#6171126)
Thanks!
Re:A Unix Utility You Should Know About: Netcat (2009) by atesti on Monday August 05, 2013 @01:51AM (#6158655)
Also check out socat: It's like netcat, but bidirectional. http://www.dest-unreach.org/socat/doc/socat.html#EXAMPLES
Re:A Unix Utility You Should Know About: Netcat (2009) by mcpherrinm on Monday August 05, 2013 @02:29AM (#6158730)
More than just bidirectional: It supports a lot of other socket types, and other shenanigans. I use socat a lot for testing network services, gluing together applications, and lots of other places where writing a little C program would otherwise be needed.
Re:A Unix Utility You Should Know About: Netcat (2009) by sprash on Monday August 05, 2013 @04:39AM (#6159001)
All of these tools were not necessary if Networking were file based, like the /net FS in Plan9.

It is the first major occasion where Unix went in a completely wrong direction. The second one was the X server.

Re:A Unix Utility You Should Know About: Netcat (2009) by justincormack on Monday August 05, 2013 @06:22AM (#6159317)
Make a fuse filesystem for networking then...
Re:A Unix Utility You Should Know About: Netcat (2009) by jvoorhis on Monday August 05, 2013 @12:52AM (#6158541)
Stupid LAN trick: you can combine nc with pbcopy/pbpaste for distributed copy/paste on macs.
Re:A Unix Utility You Should Know About: Netcat (2009) by timmow on Monday August 05, 2013 @04:09PM (#6162597)
I do something similar with local port forwarding in ssh - I can also use this to open files on remote servers in local gui editors, and to send things to notification centre - useful if you leave a long running task in the background.
Re:A Unix Utility You Should Know About: Netcat (2009) by nicholassmith on Monday August 05, 2013 @08:23AM (#6159678)
That sounds like a useful LAN trick, not a stupid one. I can't think of a situation recently where I've needed it but I'm sure it'll crop up some point.
Re:A Unix Utility You Should Know About: Netcat (2009) by sehrope on Sunday August 04, 2013 @11:39PM (#6158297)
Netcat is indeed very versatile and useful but most of the time it's used improperly when used as a server (-l mode). Unless you're doing basic network diagnostics (ex: testing if firewall ports are open) you're better off using openssl (s_server mode) or more likely good ol' SSH port forwarding.
Re:A Unix Utility You Should Know About: Netcat (2009) by stormbrew on Monday August 05, 2013 @02:19AM (#6158705)
I don't really feel like there's that many people misusing netcat out there. It's mostly useful to me as a server for hand testing client software against a known (and human-talkable) server protocol.

Is there some rash of people opening up public listening ports using netcat to... run a service of some sort? Most of the time when I need an arbitrary connection between unix machines ssh in command (not even port forward) mode is more than enough.

Re:A Unix Utility You Should Know About: Netcat (2009) by voltagex_ on Sunday August 04, 2013 @11:32PM (#6158279)
There are so many different variants of netcat:

nc, netcat, ncat, socat... I can never be sure of which syntax I'm going to get on an unfamiliar server.

Re:A Unix Utility You Should Know About: Netcat (2009) by LukeShu on Monday August 05, 2013 @12:33AM (#6158492)
nc, ncat, and netcat are all the "same". Any of them could be any of:

  * the original netcat (http://nc110.sourceforge.net/)
  * OpenBSD netcat
  * "GNU netcat" (not affiliated with GNU)
  * BusyBox netcat
  * Nmap ncat (well, this one is typically always "ncat")
They all take roughly the same, but different, syntax, like 'cp', 'ls', or any of the *nix utilities with multiple implementations.
Re:A Unix Utility You Should Know About: Netcat (2009) by chadrs on Monday August 05, 2013 @01:35AM (#6158633)
On a related note it's always annoyed me when people use "telnet" when they mean "make a TCP connection" as in "can you telnet to the port?"
Re:A Unix Utility You Should Know About: Netcat (2009) by username42 on Monday August 05, 2013 @04:24AM (#6158965)
When providing support, you have to be very precise when you ask someone to perform a check. The sentence "can you telnet to the port" is unambiguous. The sentence "can you make a TCP connection" leaves the choice of the tool unspecified. Depending of their background, some people may use ping (subject to different firewall rules), or a browser (subject to proxy configuration).
Re:A Unix Utility You Should Know About: Netcat (2009) by icebraining on Monday August 05, 2013 @07:04AM (#6159431)
Ping doesn't make TCP connections!
Re:A Unix Utility You Should Know About: Netcat (2009) by username42 on Monday August 05, 2013 @08:08AM (#6159619)
I know, but for many people, pinging the remote host is their single idea for network issue analyse.
Re:A Unix Utility You Should Know About: Netcat (2009) by pbhjpbhj on Monday August 05, 2013 @07:19AM (#6159474)
When I'm testing a mail server I'll sometimes use telnet to connect (eg to port 110), or openssl for testing secured connections. What should I be using; or is it just the nomenclature you're bothered about?
Re:A Unix Utility You Should Know About: Netcat (2009) by djeikyb on Monday August 05, 2013 @10:39AM (#6160357)
One thing I like about the original and the gnu netcat is the z option: `nc -z host port; echo $?` for quick testing.
Re:A Unix Utility You Should Know About: Netcat (2009) by platz on Monday August 05, 2013 @12:48AM (#6158532)
I'm under the impression that socat is the most versatile, but probably involves more typing for similar commands.
Re:A Unix Utility You Should Know About: Netcat (2009) by augustl on Monday August 05, 2013 @02:26AM (#6158722)
Be aware that GNU netcat and BSD netcat are incompatible. Many a time have I attempted to cat a file from a Mac to a PC running Linux, only to have found that Nothing Happens (tm). I just recently realized that installing BSD netcat on Linux solves the problem. Not sure what the actual incompatibility is, just a heads up.
Re:A Unix Utility You Should Know About: Netcat (2009) by pflanze on Monday August 05, 2013 @11:29AM (#6160661)
For my own purposes[1], I wrote these wrappers that abstract the differences between the two versions of nc that I had to deal with away:

https://github.com/pflanze/chj-bin/blob/master/netcat-get https://github.com/pflanze/chj-bin/blob/master/netcat-push https://github.com/pflanze/chj-bin/blob/master/netcat-receiv... https://github.com/pflanze/chj-bin/blob/master/netcat-serve-...

(They use 'have' from here: https://github.com/pflanze/chj-bin/blob/master/have )

[1] for example my way to transfer files between servers: https://github.com/pflanze/chj-bin/blob/master/netoffer (which depends on netfetch from the same place)

Re:A Unix Utility You Should Know About: Netcat (2009) by bartbes on Monday August 05, 2013 @06:59AM (#6159413)
If I remember correctly one of them requires you to specify the port with -p separately, and the other gets it from -l. So it's nc -l 1234 on one, and nc -l -p 1234 on the other.
Re:A Unix Utility You Should Know About: Netcat (2009) by bifrost on Monday August 05, 2013 @04:20AM (#6158950)
I just confirmed this is not the case. Could you share what you were doing?
Re:A Unix Utility You Should Know About: Netcat (2009) by augustl on Tuesday August 06, 2013 @10:15AM (#6166672)
Seems like bartbes pointed out the problem. I suppose not specifying the port correctly makes it use some default port or something like that.
Re:A Unix Utility You Should Know About: Netcat (2009) by tzury on Monday August 05, 2013 @12:24AM (#6158464)
Some more examples at wikipedia

http://en.wikipedia.org/wiki/Netcat#Examples

Re:A Unix Utility You Should Know About: Netcat (2009) by hcarvalhoalves on Monday August 05, 2013 @02:15PM (#6161783)
BSD's nc doesn't have the (arguably unsafe) -e option.