63

Is there a terminal command within Mac OSX that will allow me to use WOL (Wake On LAN) to wake up other computers? Windows has wolcmd, is there an equivalent within OSX?

I am trying to wake a computer from my rMBP, within my network. My rMBP is connected via WiFi normally, but can also be connected via Thunderbolt GbE connector. The target computer is a Windows machine that I want to wake up before I connect to it using a remote desktop connection.

2
  • $ ~/bin/wakeonlan server-mac-address-here
    – Ruskes
    Commented Jun 30, 2013 at 7:35
  • @Buscar, On my mac (OS X 10.8.4), I get -bash: /Users/Dygear/bin/wakeonlan: No such file or directory. Commented Jun 30, 2013 at 10:11

9 Answers 9

99

Install the wakeonlan package using Homebrew:

$ brew install wakeonlan

(It's a Perl script for waking up computers via Wake-On-LAN magic packets.)

When installed, you can send a "magic packet" from your Terminal to any device using its IP (Internet Protocol) and MAC (Media Access Control) address.

Here's an example of a typical use:

$ wakeonlan -i 192.168.1.255 -p 1234 01:02:03:04:05:06

The scripts takes 2 arguments, the MAC address of the NIC, and an IP address.

Note: The IP address argument is tricky and isn't what you'd think.

For a NIC on your local subnet, use the broadcast-address of this subnet. (e.g. subnet 192.168.10.0 with netmask 255.255.255.0, use 192.168.10.255)

For example, I have a Synology NAS manually configured with the IP address of 10.0.1.100 with a subnet mask of 255.255.255.0 and a router address of 10.0.1.1.

The correct IP address to use is not that of the device, but instead the broadcast-address of the subnet.

Continuing on my example, I used the following command to successfully wake up my Synology:

$ wakeonlan -i 10.0.1.255 -p 7 01:02:03:04:05:06

(Naturally, substitute the actual values of your device and network for your situation.)

You can get more information from the wakeonlan man page, man wakeonlan, or a quick glossary of commands from wakeonlan -h.

5
  • I read somewhere, that it will only wake your mac from sleep, and not when it completely powered off. And maybe it also only works on LAN, not WLAN.
    – d4Rk
    Commented Sep 11, 2016 at 15:54
  • 1
    My broadcast-address isn't as clear as your example shows, so I used this site to determine: remotemonitoringsystems.ca/broadcast.php
    – Samuel Li
    Commented Sep 29, 2017 at 19:03
  • Can this be used to wake a computer up from shutdown? It doesn't seem so. Is it possible to WOL a computer from cold boot by sending the magic packet? Apple Remote Desktop can already wake a computer up from sleep. Commented Nov 1, 2017 at 18:43
  • 2
    @MarkTomlin You asked for command line command, this is the correct answer. Commented Nov 6, 2018 at 19:35
  • 1
    A few years later, as in right now, I've accepted this as the correct answer as it clearly is. Commented Jun 26, 2021 at 19:15
66

The wakeonlan command for command-line can be added to OS X using the homebrew package manager.

23

Python comes with OS X per default. So you could use this small Python 2 script to send the wake on lan package. Save it as wakeonlan.py or something you like:

#!/usr/bin/env python

import socket
import sys

if len(sys.argv) < 3:
    print "Usage: wakeonlan.py <ADR> <MAC>     (example: 192.168.1.255 00:11:22:33:44:55)"
    sys.exit(1)

mac = sys.argv[2]
data = ''.join(['FF' * 6, mac.replace(':', '') * 16])
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.sendto(data.decode("hex"), (sys.argv[1], 9))

Use it like this:

python wake.py 192.168.1.255 00:11:22:33:44:55

Modify the IP address and MAC address accordingly. The IP address should be the broadcast address of the network.

For easy access you could make this script executable and add it to some directory in your path.

2
  • 2
    I like this solution with no installation required!
    – Samuel Li
    Commented Sep 29, 2017 at 18:30
  • MacOS uses python3 by default now
    – lacy
    Commented Sep 14, 2022 at 14:00
4

wolcmd is available for Mac: http://www.depicus.com/wake-on-lan/wake-on-lan-for-apple-mac.aspx

GUI version for $1.99, terminal version is free. Usage is just the same as its Windows counterpart.

2
  • Glad I could help :)
    – b4d
    Commented Jun 30, 2013 at 10:56
  • 15
    Why download an unsigned opaque binary from some random web site, when you could just use the open-source program in the answer below?
    – ruief
    Commented Jan 11, 2018 at 8:02
4

The RubyGems package which is stock on Mac, can also be used to install a wake on lan app. Just use the gem install wol command in terminal. It will install the activity in /usr/bin/local/wol.

This avoids having to install brew or package managers. It accepts the same arguments as the wakeonlan examples above.

As an aside, the wol tool can wake a properly configured Synology NAS.

2
  • How is gem not a package manager too?
    – WGroleau
    Commented Nov 16, 2022 at 21:56
  • 2
    You are correct that gem is a package manager, but it was installed on macOS by default and did not require compilation or additional space beyond the tool itself. Commented Dec 6, 2022 at 20:14
4

Here is a working python3 version of @J.P. Petersen's solution, you need to replace the hex-decode component, e.g. with the solution mentioned here: Decode Hex String in Python 3

#!/usr/bin/env python

import socket
import sys
import codecs

if len(sys.argv) < 3:
    print("Usage: wakeonlan.py <ADR> <MAC>     (example: 192.168.1.255 00:11:22:33:44:55)")
    sys.exit(1)

mac = sys.argv[2]
data = ''.join(['FF' * 6, mac.replace(':', '') * 16])
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
decode_hex = codecs.getdecoder("hex_codec")
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.sendto(decode_hex(data)[0], (sys.argv[1], 9))
1
  • Thank you so much for this, I was struggling to get it working!
    – bperdue
    Commented Jan 12 at 6:32
0

It's probably possible to be installed through the MacPorts package manager as well, but I don't have it installed, can't test it.

1
0

Apologies: can't upvote "@J. P. Petersen" or comment yet (don't have enough points), so an answer (late) will have to do.

@lacy is correct on Python3 now, but the script did need some mod, so here's what worked for me (since .decode no longer python3, and we need the MAC address to be bytes-like; also note simplified code and MAC address first argument, no colons); same use broadcast address (not IP address):

$ pico wakeonlan3.py

#!/usr/bin/env python
import socket
import sys
mac = bytes(sys.argv[1], 'utf-8')
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.sendto(mac, (sys.argv[2], 9))

$ chmod 775 wakeonlan3.py

$ python3 wakeonlan3.py 001451e6f3d1 192.168.0.255

-1

Just wanted to plop this out from the FreeBSD source code, for those not afraid and compiling a small c program.

FreeBSD wake command source

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Mar 4 at 21:49

You must log in to answer this question.

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