Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Wake a sleeping Mac from the network UNIX
Most modern computers offer a feature called "Wake on LAN". This is designed to allow a network administrator to turn on a computer remotely, even when it is turned off, by sending a "magic packet". This is used, for instance, to allow backup programs to run at night.

I haven't found any trace of this documented on Apple's web site, but it seems Macs also implement this feature (at least my iMac G4 does). I use this feature to turn on my iMac from my office when I want to log on using ssh (I have a Solaris machine on my home LAN that runs 24/7).

The magic packet format is very simple: it must include anywhere in the packet 6 times hexadecimal FF, followed by 16 times the Mac's MAC address (pun intended). The easiest way to do this is to send a broadcast.

Here is a Python script that does this (if your MAC address is 01-23-45-67-89-0a:
#!/usr/bin/env python
import socket
s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.sendto('\xff'*6+'\x01\x23\x45\x67\x89\x0a'*16, ('', 80))
[Editor's note: Sounds very cool, but I don't run Python ... any way to replicate this script in something that's installed on all OS X boxes? I know there are a lot of people that would probably be interested in such a solution, myself included!]
  • Currently 3.30 / 5
  You rated: 4 / 5 (10 votes cast)

Wake a sleeping Mac from the network | 36 comments | Create New Account
Click here to return to the 'Wake a sleeping Mac from the network' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Perl script to do the same thing
Authored by: Cadre on Feb 20, '02 10:48:38AM
Free App Does the Trick
Authored by: Boris Darling on Feb 20, '02 11:39:32AM

As Yoda would say, "Silly rabbits! Know you not about 'Wake 550'? Hmm?"

"Good is the way of waking by mac addresses. And good is the way the force makes the app remember frequently used mac address."

Yoda and I only wish that the app supported linking a name to each mac address. You know, so you can pick "PowerBook" or "G3 Workstation" off your Wake 550 list. Maybe in a future release...

[ Reply to This | # ]
Free App Does the Trick
Authored by: sjonke on Feb 20, '02 12:13:21PM

It does work, but I wish it would allow me to set a name for each address so I could easily pick a particular computer from a list. Anything like this out there?

[ Reply to This | # ]
Talkin' to the Author
Authored by: Boris Darling on Feb 20, '02 12:44:12PM

Instead of just wishing, I sent the author, "550 Software", who I suppose is a student at the University of Minnesota. Here's his website:

I asked if he could please add this feature.

I have included a certain amount of filth to please the gentlemen of the
press. They have proved ungrateful.

Charles Baudelaire

[ Reply to This | # ]
Talkin' MORE to the Author
Authored by: Boris Darling on Feb 20, '02 06:58:25PM

I just got an email back from the author, and he says he's going to add my feature request, and he may release the new version as early as tonight!


[ Reply to This | # ]
RE: Wake on Lan
Authored by: Anonymous on Feb 20, '02 01:14:27PM

The original poster stated that he was remotely turning on his iMac. I wonder if this is a misprint when he probably meant to say waking it from sleep.

The original Wake on Lan, which involves booting up a machine that is turned off, is not supported on the macs. I could be wrong but I think this is the case. PC's that have this capability have an additional power cable from their ethernet cards to the power supply. The ethernet cards are always on when the machine is shutdown. That way they can receive the cmds from an admin to turn them on remotely.

Wake from Sleep over the network has been supported I think beginning with last years machines and OS 9.1. This feature is fine and dandy, but I have never understood while apple hasn't supported the remote booting option of wake on lan. If we can schedule a startup time for the mac, then it shouldn't be that much more to support the booting from shutdown.

[ Reply to This | # ]
RE: Wake on Lan
Authored by: jknecht on Feb 20, '02 06:12:20PM


[ Reply to This | # ]
RE: Wake on Lan
Authored by: phillipc on Sep 01, '02 03:04:58PM

I am not sure if Apple currently uses a feature of Wake On LAN for turning a Mac on but I do know that Apple had software before Wake On LAN existed (similar to Apple Remote Desktop ) that would allow Admins to start a Mac remotely.

[ Reply to This | # ]
RE: Wake on Lan
Authored by: sandeepw on Jan 09, '06 05:52:10AM

I have MAC machine (version iMAC G5). Could anybody tell me that whether I can wake up this from shoutdown using Wake on LAN utilities. I have already started this machine from sleep mode. If anybody have any idea, please let ame know ASAP as its urgent for our project requirements.

Thanks & Regards,
Sandeep Wadhwa

[ Reply to This | # ]
Wake from sleep or power off?
Authored by: Loren on Feb 20, '02 01:28:12PM

I can wake my dell computer at work, even if it is shut down. But it seems I can only wake my Powermac G4 (Quicksilver) if it is asleep.

Is there a setting somewhere I need to change?


[ Reply to This | # ]
Wake from sleep or power off?
Authored by: Boris Darling on Feb 20, '02 07:05:31PM

Nope, and we can blame Apple. Wake on LAN is a feature built into the NIC (the Ethernet card), and then the OS must support it too. This is one of the things, in the PC world, that determines one the differences between a manufacturer's home computer line (like Compaq Prosario), and business computer line (like Compaq Deskpro).

I'm hoping that G4's will eventually get a firmware upgrade that will support this in OS X. But I'm not holding my breath...

[ Reply to This | # ]
Wake from sleep or power off?
Authored by: digitalone on Dec 07, '02 10:10:20PM

I have a Quicksilver 2002 800mhz on 10.2.2 and I have never been able to use the "wake for Administrative access" function through ssh, eihter from a windowz machine or a Mac over the network. Are there any known issues, and how do I troubleshoot this issue? Apple doesn't really support this function because "it's in the command line", and nothing I've tried short of a firmware update [which I haven't done] works.
Any help would be much appreciated.

Sean the digital one...

[ Reply to This | # ]
Python not required
Authored by: SeanAhern on Feb 20, '02 04:16:39PM

Editor, the python example that was given is not to be run on the machine to wake. It's meant to be run on some other machine that you have access to. The python example could be written in any other language you want. It just sends particular data on a socket. The machine to wake doesn't need to be running anything in particular - just listening on the other end of the socket.

(This is all assuming, of course, that I read the article correctly...)

[ Reply to This | # ]
Python not required
Authored by: aranor on Feb 20, '02 04:30:06PM

You read the article correctly, but not the editor's comments. The editor wanted a version of the script written in something else (like a shell script using sh) that's installed on all OS X machines so he could use it. This is because the Editor doesn't have/use python, so he can't use the python script.

As a side note, I second the editor's request.

[ Reply to This | # ]
Python not required
Authored by: The Jet Coaster on Feb 20, '02 08:05:24PM

Spiff up the python script and just compile the python script into an Terminal executable. Works at least on Linux.

[ Reply to This | # ]
Python not required
Authored by: gteague on Feb 21, '02 04:08:41AM

there was an author's comment on the version tracker page which should solve this. i quote:

'To [APi]TheMan From Developer: Look under the source folder for a file named "wakeonlan". This file is really a compiled perl script which my program uses. Therefore you can use that directly from the command line.'

Many thanks to everyone -- I was needing exactly this feature (wake from cli). I have a server running 24/7 and a sleeping g4/733 workstation. I can only telnet into the server from work and sometimes I need a file from the workstation. This will be far easier than firing up TBk2 on my laptop and dialing up the workstation.


[ Reply to This | # ]
Python not required
Authored by: victory on Feb 22, '02 12:49:29AM

A couple of months back, when I first discovered that my Cube could be woken from sleep by 'magic' wake-on-LAN packets, I found a short C program that would do just that. It was more of a test program and had the MAC address of the target computer hard-coded. It was evidently written for Linux, but since it used the usual BSD-style socket calls, I did get it to complie and work under OSX. I didn't mess with it any further because of other projects.

If anyone is interested, I can try to look for the source or at least a link to where I found it.

[ Reply to This | # ]
Authored by: victory on Mar 05, '02 06:02:53PM
Since at least one person has asked, here's the link to a small C prg that will send the magic WOL packet.
You will need to add the following line:
#include <unistd.h>
to the wakelan.c file, but it should configure/make just fine after that. This is a decent page of info for anyone interested in WOL.

[ Reply to This | # ]
partial wakeups and crash
Authored by: thwaite on Feb 22, '02 01:20:15PM

Hi all,

Wake550 does its part fine, but not every Mac responds well. My DP800 hears the magic packet,
cranks up its fan and hard disk ... then freezes and has to be rebooted. Any ideas?

When manually prodded this G4 quicksilver normally wakes from sleep pretty well,
although until I shuffled its RAM I was an
unhappy participant in the thread on Apple's support board (totalling 100+msgs) discussing the
widespread difficulties some G4's have waking up reliably. In OS9 that's often due to a weird
extension but there's no explanation yet for OSX.

Thanks - Ron

[ Reply to This | # ]
And from Windows?!
Authored by: Mi And on Feb 23, '02 03:22:01AM

I know it would be nice if we all had Macs on our desktops, but the most common situation would be to start your home OS X machine from a PC in your office, running W2K for example.

Any easy solution for that? (I know I could install Python or Pearl and running those scripts from W2K, but that's a huge task. There must be some App to make that easier.)

[ Reply to This | # ]
And from Windows?!
Authored by: Mi And on Feb 24, '02 08:00:48AM

It's nice if one is able to answer one's question himself ;)

A lot of Windows-tools can be found here:

The one that worked best for me (in my local network at least, waking an iBook from my PC) is the GUI-thingy from AMD, linked here as "Magic Packet Utility".

[ Reply to This | # ]
Another Windows option...
Authored by: jmordoj on Sep 26, '02 08:35:25AM
I have discovered another very useful Windows Application that lets you wake up a Mac using the "Magic packet technology" (I think it is an AMD technology), that does exactly that; sends a "wake up" packet to the Mac an wake it up. It is a very simple GUI app that asks for a MAC address (you can get it from the network preferences), and an IP. It works for my every time (iMac 500 slot-loading CD). You can get the program here:

[ Reply to This | # ]
Authored by: stilesja on Jun 18, '02 03:00:26PM

It looks like you are sending this on port 80 of a particular IP address. So, if I have port 80 of my router fowarded to my Mac and I send this request to the IP address of the Router should it then wake up the Mac?

I would however need to send the MAC address of the computer not the Router right?

Would this work? It would be very cool if it does since I am often gone all week for work and it would be nice to be able to turn the computer on and off remotely...

[ Reply to This | # ]
Authored by: ajmas on Aug 30, '02 01:49:05PM

It only allows a sleeping computer to be woken up. If the system is shutdown then this won't work. The MAC address must be that of the computer you wish to wake.

[ Reply to This | # ]
Authored by: scifiman on Dec 08, '02 09:31:00PM
The original post seems to indicate port 80 right after the broadcast address, however according to WakeUp Page, a UDP packet is sent on port 9. Can anyone clarify which port(s) need to be forwarded for WOL to work thru a router? Thanks.

[ Reply to This | # ]
Authored by: nevyn on Feb 09, '03 02:58:58PM

Just about any port you want.

[ Reply to This | # ]
Authored by: PeteVerdon on Aug 14, '04 08:05:15AM

The port you send to is entirely irrelevant. You could send it on another IP protocol such as ICMP that doesn't have ports at all, or on MS or Apple's old systems (NetBEUI/AppleTalk) or even plain raw Ethernet. All that's required is that the network card see a certain sequence of bytes on the wire.

It's common to use UDP port 9 because this is the "Discard" port from the early days of IP. Using this means WOL won't interfere with anything else you might have running. However, using some other port might be handy if it's already opened to allow another service to run. TCP port 80 would be a good example - anyone who runs a Web server would be able to use WOL on 80 without any further configuration.


[ Reply to This | # ]
so, does it work?
Authored by: ynolo on Sep 01, '02 06:29:22PM

will the script above turn on a modern Mac (G4,iMac,PBK) that is off over a LAN or will it only wake it up from sleep?

[ Reply to This | # ]
You do have Python...
Authored by: jules on Sep 01, '02 07:14:34PM

...if you're running OS X 10.2 and installed the goodies from the Developer disk. Pull up a shell and type 'python'. It'll run 2.2 for you.

[ Reply to This | # ]
Wake on LAN using PHP
Authored by: karnat10 on Mar 29, '04 08:22:00AM
The magic packet has to be sent over UDP because you won't be able to open a TCP connection with a sleeping host. I've written a PHP function which does all the magic:
function wakeonlan($ip,$mac) {

$socket = fsockopen("udp://".$ip,9,$errno);

if (!$errno) {
	$magicpacket = str_repeat(chr(0xff),6).str_repeat(pack("H*",$mac),16);
Call the function like this:
where the first parameter is the IP address (or hostname) and the second parameter the MAC address of the computer to wake.

It works tip top with my AluBook G4.

[ Reply to This | # ]
Wake a sleeping Mac from the network
Authored by: regulus on Nov 21, '06 11:44:20AM

Thanks, worked great for me on my home network with one additional change, I needed to also change in the script with the IP address of the computer I wanted to wake, otherwise I got an error... socket.error: (13, 'Permission denied')

Note: I have a standard MacOSX 10.4.8 install with the developer tools and the script just worked. No need to install python.

Here's the steps:
1. paste the script into a new text document
2. changed the MAC address and IP address to the computer I want to wake
3. saved it as wakeonlan
4. made it executable with chmod a+x wakeonlan
5. set the Energy Saver preference to allow wakeonlan on the computer I wante to wake

[ Reply to This | # ]
Wake a sleeping Mac from the network
Authored by: fladnag77 on Jan 30, '07 07:56:43AM

To get this script to work with the "broadcast" address (which is useful if you don't know the sleeping machine's IP (when it is dynamically assigned using eg DHCP)), I added one line:

#!/usr/bin/env python
import socket
s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.sendto('\xff'*6+'\x00\x01\x02\x03\x04\x05'*16, ('', 9))

and also changed the port to 9 (the "discard" port).

[ Reply to This | # ]
Wake a sleeping Mac from the network
Authored by: pisosse on Jul 10, '07 03:36:37PM

any development on this issue?

I'm working on incorberating a button on a webpage to wake my macmini wich runs a a small rumpus server and then log on to it..


[ Reply to This | # ]
Wake a sleeping Mac from the network
Authored by: on Mar 29, '08 05:19:46PM

Thanks a lot for the data - I am a sysadmin and I really needed to wake my macs up to run backups. I wasn't in the office, working over a VPN - very happy when ssh finally got through..

One datum of note: For your python script to run on a Linux system (and I assume Unix [read Mac] as well) you need to add the following line just after you declare the s variable:

By the way, highly important the point Yoda made is; for young apprentice Jedis, better nothing is than GUI.

But listen well, Anakin - when you are not in the office or just can't be bothered to manually back up every night (no matter how nice the GUI is for waking up the remote computer), copy the python code into a file, make it executable, and have your shell script execute it before it runs the backup commands (rsync over ssh, anyone?)

Oh, and don't forget to throw "sleep 60" after the wakeup script, so that you give your mac(s) time to get out of bed before you try getting in and doing your thing.

[ Reply to This | # ]
Wake a sleeping Mac from the network
Authored by: elightbo on Apr 24, '08 11:52:03AM

This helped out a lot. I couldn't figure out why it wasn't working when going from my Ubuntu server to the MacBook. Also had problems due to not delaying the script. Wish I would have read this first!

[ Reply to This | # ]
Wake a sleeping Mac from the network
Authored by: pdan on Sep 07, '09 02:31:07PM
Actually your python script also needs to set SO_BROADCAST:

#!/usr/bin/env python

import socket;

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM);
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1);

s.sendto('\xff'*6+'\x00\x24\x36\xf0\xc4\x69'*16, ('', 80));

[ Reply to This | # ]