I'm trying send a WOL packet from a bash script under Mojave, much like https://stackoverflow.com/a/31588036/9370650, without any third-party utilities, such as the nifty https://github.com/jpoliv/wakeonlan.

I don't, however, seem to be able to successfully broadcast anything at all to on port 9 using netcat.

If I listen to UDP port 9 like this:

$ nc -uv -l 9 -w0

netcat then reports the WOL packet when I run the perl-based wakeonlan script I mentioned above.

But, if I try to do my own UDP broadcast to, like this:

$ echo "hello" | nc -vu 9

it isn't seen by my listening instance of netcat.

For the record, the output from my attempt to broadcast looks like this:

found 0 associations
found 1 connections:
     1: flags=82<CONNECTED,PREFERRED>
    outif (null)
    src port 51674
    dst port 9
    rank info not available

I'm not a networking expert, so I'm likely misunderstanding something here.

Any thoughts on what I'm doing wrong?


I've likely answered my own question:

The BSD version of netcat included with macOS lacks the -b (broadcast) flag.

And even though is a special global address for broadcasting to the entire subnet, simply sending to it apparently isn't enough to imply/accomplish a broadcast without that missing -b flag.

So, my impression is that the macOS version of netcat simply won't do what I'm trying to do.

If I were to install an alternate netcat implementation using homebrew or some other source, it might accomplish it--but at that point, I'd rather just depend on having wakeonlan installed.

I'll leave this answer here, but unaccepted, hoping that someone with more low-level networking know-how provides a better answer at some point.

Edit: Also, if one were going to install other software due to netcat limitations, it looks like socat (described as "netcat on steroids") would likely be something to seriously consider, instead of just an alternate version of netcat.

You must log in to answer this question.

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