Is anybody else not able to get nc -lp 8888
working on Mac OS X? Is there another way to get this to work?
5 Answers
It looks to me as if the -p
option does nothing on the OS X version of netcat. To get it to work, I must do nc -l localhost 8888
.
-
9Unless installed from homebrew, then
nc -l -p 8888
works. Commented Dec 3, 2012 at 13:27 -
4From
man nc
:-l ... It is an error to use this option in conjunction with the -p, -s, or -z options. ...
You probably want to just stick with @kzh's command there– fatuhokuCommented Oct 11, 2013 at 18:41 -
@fatuhoku I just checked my manual, and yest it does say that in there, but the weird thing is that if I do
nc -lp 8888
ornc -l -p 8888
it will then take-p
to mean listening port. So my distributed copy does not listen to its own manual!– kzhCommented Oct 11, 2013 at 20:31 -
Agreed! Flags are a bit too expressive... it should have just refused to do any useful work, output a message and quit!– fatuhokuCommented Oct 11, 2013 at 21:02
-
1
Here's how this is working for me on OS X 10.10, with either the installed BSD version, or the one from Homebrew:
BSD Version
When using the BSD version that ships with OS X, a server can be started like this
/usr/bin/nc -l 9999
Homebrew
- Install using Homebrew:
brew install netcat
- This will install v0.7.1 of http://netcat.sourceforge.net/
- One can use either the
nc
ornetcat
command.nc
is an alias fornetcat
.
To start a server:
nc -l -p 9999
To start a client:
nc targethost 9999
To get the manpage of this version, one needs to use man netcat
, as man nc
will open the manpage of the BSD version.
I needed to test a web service over SSL, which ncat (made by the nmap team) supports.
brew install nmap
ncat -C --ssl api.somecompany.com 443
nc on MacOS has too many bugs, and Apple did none patch for years. the netcat from homebrew is a very low version. use ncat from nmap instead
-
2+1, as of today,
netcat --version
is0.7.1
(2003) forbrew install
ednetcat
. Terrible.– ijosephCommented Oct 20, 2020 at 22:29 -
-
"
nc
on MacOS has too many bugs" -> I can only confirm this. 😕 Fiddling around with it today and facing some inconsistent behaviours. I believe this version of nc from 2005 is the one that they're still using. Ended up using socat instead:brew install socat
. Commented Apr 30, 2022 at 21:10
Based on the nc manual from Mac:
NC(1) General Commands Manual NAME nc – arbitrary TCP and UDP connections and listens
-l Used to specify that nc should listen for an incoming connection rather than initiate a connection to a remote
host.
It is an error to use this option in conjunction with the -p, -s, or -z options. Additionally, any timeouts specified with the -w option are ignored.
Working example:
nc -lv 9001
nc -lp 8888
works on my Ubuntu box.