1

I tried running nc -lnvp 1234 > filename.log on my macOS today and it returned this error saying I need to specify a port number, while I specified the port number on my command.

This command always works on my Debian and Ubuntu, is there a reason why its different on macOS?

enter image description here

I tried the same command in my Debian based machine and it worked.

What should I do?

3
  • 1
    I can't figure out why it's complaining (your syntax looks right according to the usage text there), but do keep in mind that just on Linux there are 5 or 6 different programs all named "nc" with similar but not identical usages – even Debian has two – so it's not that surprising that Apple wrote their own for macOS.
    – grawity
    Commented Dec 3, 2022 at 10:42
  • i did man nc and it says i am running netcat, however i cant seem to get the version no matter what command i use, and its not specified in the manual what option returns the version.
    – PsOom
    Commented Dec 3, 2022 at 10:48
  • Broader picture: "everything is a file" in *nix unfortunately does not apply to network sockets. See this answer: "if Unix had integrated TCP/IP I/O into the filesystem from the start, we wouldn't have the netcat vs socat vs Ncat vs nc mess, the cause of which was the same design weakness that lead to the disk imaging and wiping tool proliferation on Windows: lack of an acceptable OS facility". Plan 9 fixed this design misstep and I wish all Unix-like systems work out a single universal interface some day. (Silly me?) Commented Dec 3, 2022 at 11:19

1 Answer 1

2

From ss64.com man nc/netcat

-l  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.
2
  • why not?, if im waiting for a connection does netcat use a random port for that connection and why is it different on linux where i have to specify a port number?
    – PsOom
    Commented Dec 3, 2022 at 10:59
  • I have no idea. You'd have to ask Apple.
    – Tetsujin
    Commented Dec 3, 2022 at 10:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .