Mac Discussion

Get help with your Mac hardware and software. Discuss Apple and its products.

[Advanced]
Jump To:

Goto Thread: PreviousNext
Wake Mini from a remote location?
Posted by: Mok (IP Logged)
Date: March 29, 2008 04:29PM

Hi folks,
I have a Mac Mini that I'm using as a media library server for my iTunes music library. I want to be able to access the computer occasionally while I'm at work, so I've enabled file sharing with my admin password and opened that port on my Airport Extreme router. My problem is that if I want to access the Mini, it has to be awake. Since I don't always know when I want to get stuff from there, I'd rather have the Mini sleeping until I need something. I have enabled the "Wake when administrator access" preference, and have been able to send it a magic packet from my other computer at home (also connected to the AEBS). However, I'd like to wake the Mini from work, which is technically 'wake-on-WAN'. I have set the AEBS to port forward UDP port 9 to the Mini's IP address at UDP port 9. Then I've tried the public utilities at dslreports and depicus to send it the magic packet, but it doesn't wake up. I've also tried Wake-On-LAN OSX and Wake550. These both work when I'm on the actual LAN, but nothing seems to work when I'm off it. Is there anything I'm missing in order to get this working right? Does the AEBS simply drop that request and I'm out of luck? I've considered just leaving the Mini on, with drives-spin-down options checked, but I think asleep would save more energy... That's really the only reason for trying this. Thanks...

Re: Wake Mini from a remote location?
Posted by: Don Andrachuk (IP Logged)
Date: March 30, 2008 03:08PM

These may be helpful:

[murphymac.com]

"Does the AEBS simply drop that request and I'm out of luck?"

Could be:
[arstechnica.com]
"Unfortunately, Apple's Airport Extreme base stations won't turn packets coming in from the Internet into Ethernet broadcasts, so if you have one of those, you'll have to let sleeping Macs lie."

Re: Wake Mini from a remote location?
Posted by: Mok (IP Logged)
Date: March 30, 2008 04:25PM

Thanks for those links - it's pretty much all info I'd already consumed, but in a tidier fashion. So I've just been going about trying all of the shareware, freeware, and internet based utilities in hopes that I could find something that worked. Looks like this one is the only one that does the trick:

[www.rshut.com]

I wish I knew what this one does that the other ones all don't do, but my AEBS (current N model) passes that packet on to my Mini over the internet, and it wakes up. It was totally a shot in the dark, but one out of many is all I needed. Now if someone would only write whatever RShut is doing into a little Mac app, I wouldn't have to rely on their site... Still, I'm thankful to find something that works...

Re: Wake Mini from a remote location?
Posted by: Don Andrachuk (IP Logged)
Date: March 31, 2008 12:29AM

Excellent. Thanks for the info.

Re: Wake Mini from a remote location?
Posted by: markmuir (IP Logged)
Date: April 1, 2008 12:14PM

I got this working with my Mac mini and AEBS (802.11n, Gigabit ethernet) by configuring the NAT to forward public UDP port 9 to UDP port 9 on my Mac mini's IP address of 10.0.1.200.

I've written an AppleScript to perform the remote wake, and here it is. Just create a new script in ScriptEditor, and copy and paste the text that follows, then save it as an application bundle. Then you can run it like an application, e.g. by double clicking it in the Finder. It asks you the MAC address of the mini, and the external IP address. These are remembered between calls (but it will ask you each time). If you find that annoying, you can modify the script to specify the values you want in the 'property' fields, and then remove the 'display dialog' lines.


(*
Wake on WAN - by Mark Muir (2008-04-01)

Sends a magic UDP packet to a remote machine to wake it up from
sleep.

If you want to use it remotely (over the internet), you must
configure your router to forward public UDP port 9 to private UDP
port 9 on the normal IP address assigned to your machine that you
wish to wake.

You can also use this script locally (from a machine on the same
network) by specifying the broadcast IP 255.255.255.255.
*)

property MAC_address : "01:a2:b3:c4:d5:e6"
property WAN_IP_address : "255.255.255.255"

on run
-- Get the MAC address of the remote machine to wake (remove these two lines if you don't want to be asked).
display dialog "Enter the MAC address of the machine you wish to wake:" default answer MAC_address
set MAC_address to the text returned in the result
-- Get the remote WAN IP address (remove these two lines if you don't want to be asked).
display dialog "Enter the external IP address of the remote machine (or 255.255.255.255 for local use only):" default answer WAN_IP_address
set WAN_IP_address to the text returned in the result

-- Now perform the remote wake, by sending a magic packet on UDP port 9 to the given WAN IP address.
set command to "/usr/bin/php -r " & quoted form of ("$mac = " & quoted form of MAC_address & "; $ip = " & quoted form of WAN_IP_address & "; " & "
/*
* Create the Magic Packet. This consists of the sequence
* FF FF FF FF FF FF followed by the MAC address repeated
* 16 times.
*/
$mac_bytes = explode(\":\", $mac);
$mac_addr = \"\";
for ($i=0; $i<6; $i++)
$mac_addr .= chr(hexdec($mac_bytes[$i]));
$packet = \"\";
for ($i=0; $i<6; $i++) /*6x 0xFF*/
$packet .= chr(255);
for ($i=0; $i<16; $i++) /*16x MAC address*/
$packet .= $mac_addr;

/*
* Send the magic packet over UDP to the specified IP address.
*/
$port = 9;
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, TRUE);
socket_sendto($sock, $packet, strlen($packet), 0, $ip, $port);
socket_close($sock);
")
do shell script command
end run


Re: Wake Mini from a remote location?
Posted by: Mok (IP Logged)
Date: April 1, 2008 01:43PM

OK, that script is totally cool. However, now I have a new addition to this. My Mini won't wake up from this call if it's been asleep for a while. For example, if I am at home and the computer is awake, I can put it to sleep, go over a friend's house, and wake it up from there, and everything's cool. But, if I put it to sleep at night, wake up in the AM, go to work, and try waking it up, it don't wake. I don't know if it's the AEBS losing its memory to know where my Mini is located (10.0.1.250) or what. I have the Mini set to manual address, so it's not getting a new one over DHCP. I tried setting the AEBS to lease DHCP for four days instead of four hours, hoping that that would do the trick, but no dice so far. It's frustrating because this should be easy to do, and it's ultimately better on energy, environment, and mechanical life to keep the Mini asleep until I want it awake. My guess is that the AEBS doesn't 'remember' where on the network the Mini was, and so if that IP isn't registered with the AEBS when the UDP request goes out, the AEBS doesn't know where to send that info and just drops it like a nice firewall should. Is there a secret to getting that request passed on to the whole network behind the AEBS? It's MAC address-specific, so the Mini would be the only one to care about it.

Re: Wake Mini from a remote location?
Posted by: markmuir (IP Logged)
Date: April 1, 2008 01:57PM

Oh yeah, thanks for the info - it was only after reading your comments that I figured out what was needed to make the script work from outside the local network.

I haven't used this feature long enough to see if the same behaviour happens with my set up. However, I have been using wake on LAN with a Mac Pro at work for a long time (always from inside the LAN), and it can be off for days at a time but still wakes. So I think it is unlikely to be a problem with the mini.

Your explanation sounds plausible. You're right that the packet can be sent to any machine, and will be ignored unless the MAC address matches. Normally, this packet is sent out over the broadcast address 255.255.255.255 to reach all machines on the local network. It also works on the AEBS (from inside the LAN) on 10.0.1.255, which is its own broadcast address. So I tried configuring the AEBS' NAT port forwarding to use 10.0.1.255 instead of the mini's fixed address. Airport Utility allowed me to enter that with no complaint, however it didn't work - the packets were just dropped. Which I guess is reasonably sensible, from a security point of view.

Anyone else have any ideas?


Re: Wake Mini from a remote location?
Posted by: Mok (IP Logged)
Date: April 1, 2008 09:15PM

Don's ars technica link above is pretty much the word, especially the passage:

"The problem is that when the computer sleeps, there is no network stack to keep track of an IP address and reply to ARP packets. So in order to make the Ethernet card see the magic packet, this packet has to be a broadcast."

and then:

"Unfortunately, Apple's Airport Extreme base stations won't turn packets coming in from the Internet into Ethernet broadcasts, so if you have one of those, you'll have to let sleeping Macs lie."

I think the "network stack" as mentioned is probably valid in the AEBS for a little while after the Mini goes to sleep, but then gets trashed on some periodic routine. My next plan of attack is to set the Mini to wake up every day at the time I get to work, then access it from there and get what I need, then put it back to sleep via VNC. That might be the only solution with an AEBS. Unless anyone has any idea behind AEBS' not-broadcasting-packets behavior and how to hack that bit...


Re: Wake Mini from a remote location?
Posted by: markmuir (IP Logged)
Date: April 4, 2008 06:25AM

I think I might've found a solution:

Rather than setting the mini to have a fixed IP address via Mac OS X (DHCP with manual address), do this in the AEBS instead, using a DHCP reservation (i.e. assign a fixed IP to a computer with a given MAC address). Instructions can be found here (in the second post):

[discussions.apple.com]

I haven't been able to test it properly, as my mini seems to get woken up by something during the night, but I did manage to wake it remotely after it having been off for 6 hours. Not sure if this is longer than before...

Re: Wake Mini from a remote location?
Posted by: Mok (IP Logged)
Date: April 4, 2008 09:47AM

I think it's still the same. That MAC fixed addressing was one of the things I tried as well - it seems to hold for a short time (several hours) but ultimately fails until woken again by LAN or the Mini itself. You'd think that that entry in the Airport settings would hold indefinitely and allow that packet to pass at any time, but it still depends on the Mini having registered at some recent point in time.

I now have a scheduled wake and sleep routine for my Mini that seems to do the trick. I scheduled it to wake at 10am and sleep at 10:15. Then I can wake from WAN for some time after, and then each time it wakes, that wake "license" is extended again for several hours. This is inelegant, but it is the only way I can see to a working solution. That is, of course, until the next 'update'...



Sorry, only registered users may post in this forum. Click here to register now.