Netcat on Mac OS X

33

12

Is anybody else not able to get nc -lp 8888 working on Mac OS X? Is there another way to get this to work?

kzh

Posted 2010-03-03T01:50:08.973

Reputation: 3 213

How does it not work? Does it return an error? – heavyd – 2010-03-03T01:58:55.870

I am not near a mac right now, but it returns the useage. nc -lp 8888 works on my Ubuntu box. – kzh – 2010-03-03T15:50:02.510

Had never heard of this until reading a book on Docker. They also mention something called socat, which is supposedly this command on steriods. More info here https://stackoverflow.com/questions/16808543/install-socat-on-mac and here https://linux.die.net/man/1/socat and here https://www.youtube.com/watch?v=ZnwZA1GRqkw

– JGFMK – 2019-09-26T08:57:31.833

Answers

36

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.

kzh

Posted 2010-03-03T01:50:08.973

Reputation: 3 213

Works also with nc -l 8888 – polym – 2015-06-19T10:49:14.573

No matter the man page said that it is an error to use -p option in conjunction with the -l option. Actually, only nc -l -p 8081 work in my mbp. That's crazy. :( – andy – 2016-03-01T03:09:05.960

8Unless installed from homebrew, then nc -l -p 8888 works. – user1338062 – 2012-12-03T13:27:14.740

2From 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 – fatuhoku – 2013-10-11T18:41:37.917

@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 or nc -l -p 8888 it will then take -p to mean listening port. So my distributed copy does not listen to its own manual! – kzh – 2013-10-11T20:31:56.630

Agreed! Flags are a bit too expressive... it should have just refused to do any useful work, output a message and quit! – fatuhoku – 2013-10-11T21:02:36.817

14

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 or netcat command. nc is an alias for netcat.

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.

nwinkler

Posted 2010-03-03T01:50:08.973

Reputation: 245

5

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

https://nmap.org/ncat/

Colin

Posted 2010-03-03T01:50:08.973

Reputation: 324

4

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

J.Z

Posted 2010-03-03T01:50:08.973

Reputation: 41