Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This tool is like netcat on steroids. Definitely part of my stable toolbelt.


Whenever someone mentions netcat or nc I always ask "which one?". There are at last count 3 different implementations, all subtly incompatible. Which is another reason why socat is better since there's only one to deal with.


How do you refer to each implementation & what are some of the subtle incompatibilities?


The original one is the "TCP/IP Swiss army knife" released in 1995:

https://nc110.sourceforge.io/ (original release: https://seclists.org/bugtraq/1995/Oct/28)

Although it is "freely given away to the Internet community" with "an obligation to give credit where due", at least OpenBSD and GNU have seen the need to write their own versions under their project licenses:

GNU netcat: http://netcat.sourceforge.net/

OpenBSD nc: https://man.openbsd.org/nc.1

(The OpenBSD version has been ported to at least FreeBSD and Apple Macintosh OS.)

All of them have the same basic telnet's `host port` syntax for outbound TCP connections, but annoyingly the syntax for opening a local listening TCP socket varies. Say, you want to open a TCP socket listening on port 1234 (local), and a confirmation when it is ready:

The original and GNU netcats: netcat -v -l -p 1234

BSD netcat: nc -v -l 1234


That makes 4 implementations, because nmap also has one (https://nmap.org/ncat/).


Dammit, they have of course gone with the BSD syntax for opening a local listen socket (ncat -l 1234):

https://nmap.org/book/ncat-man-examples.html

Means half of implemations use `-l -p 1234` and half `-l 1234`.


Does BSD netcat give an error if you include the -p?


Yes, the manual explicitly notes that -p can not be used with -l: https://man.openbsd.org/nc.1

And this is indeed enforced, see line 424: http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/nc/netc...

However, at least Debian ships a ported version of BSD's netcat. They actually apply a patch to allow using -p and -s with -l for consistency with traditional netcat: https://sources.debian.org/patches/netcat-openbsd/1.217-3/us...


Indeed. There are examples for making local/remote shells. It can make a pty, use setsid() to be a daemon, reset the terminal state, then listen(), etc, all in a one liner. Or route a serial port over ip via ptys in raw mode, again, with a one-liner.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: