Monthly Archives: June 2021

WOL = Wake-on-lan

How to make a Wake-on-LAN (WOL) wakeup call to a PC from your Mac OS in the same network or from Internet.

So the case is you have a home PC (Windows 10 desktop) running behind a Synology NAS, which is always connected to the Internet. The NAS is always on, but the PC is rarely accessed just for some special software installed on it.

To access the PC in my home network I have setup:

  • OpenVPN server setup on the Synology
  • Windows 10 Pro version which allows Remote desktop connection

So to use the software on the PC remotely you have t setup on you Mac OS:

  • OpenVPN client in order to connect to your home network – Tunnelblick (free)
  • Microsoft Remote Desktop app (free)

And this is working fine. But… You may want to sleep the PC and wake it only when you need it.

In order to be able to wake the PC you need to allow this feature in the BIOS of your PC. Also check the settings in Windows.

And then you have two cases:

A) Wake PC from Mac in the same network (WiFi):

Check this Q&A:

https://apple.stackexchange.com/questions/95246/wake-other-computers-from-mac-osx

I liked the Ruby way:

The RubyGems package which is stock (installed by default) on Mac, can also be used to install a wake on lan app. Just use the “gem install wol” command in terminal.

   gem install wol

It will install the activity in /usr/bin/local/wol.

As an aside, the wol tool can wake a properly configured Synology NAS or my Home PC.

cd /usr/local/bin

Now you have “wol” command script in this directory.

Create a new script:

sudo nano wol_pc
/usr/local/bin/wol 70:85:C2:70:23:8D

Use keys to save & exit:
^O , Enter
^X

sudo chmod +x wol_pc

This is the simple way, but not so common in use. Usually you are away and want to connect to the PC, do some work and leave without to go home for this task. Then see case B)

B) Wake PC from Mac NOT in the same network using VPN connection and Synology NAS to send the Wake-on-LAN signal.

Mac –(internet)–> Synology VPN server –(local network)–> Home PC

The WOL signal is send on port 9 using the broadcast address in your network. The issue is that using VPN you may have issues to send this WOL signal through the VPN tunnel and wake the PC.

The solution I implemented is:

to have a web page in my local network hosted on my NAS. By opening this page in my browser (when I am connected with the VPN) it will send locally from NAS the Wake-on-LAN(WOL) signal and wake the PC as if I am at home on my NAS.

Enable Synology “Web station” in order to be able to be able to open a page in my Mac OS browser.
https://kb.synology.com/en-us/DSM/tutorial/How_to_host_a_website_on_Synology_NAS

Create “wakeonlan.py” and “wol.php” page

/volume1/web/wakeonlan.py

!/usr/bin/env python
import socket
import sys
if len(sys.argv) < 3:
  print 'Usage: wakeonlan.py (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))

So calling this in shell/terminal:

python wakeonlan.py 192.168.10.255 FF:85:C2:70:23:8D

Will send a message on port 9 for the specified Network MAC Address!

Useful info: You cannot wake-up your PC by simply making PING to its IP address, because in Sleep state it does not keep/have IP address (even if it is fixed on your router or the PC!).
Wake-on-LAN relies on the NIC (network interface card) to be the only not-sleeping device which waits the wakeup call on port 9 and it recognises calls addressed to it by its MAC address (e.g. FF:85:C2:70:23:8D as in the example above).

Activate in “Package center” the “Web station”
in Web station (for DSM ver 6.2) :
–> “General settings” –> select PHP version: e.g. 7.3
I have NOT enabled the personal web sites!!! If you have enabled them, then your web directory will be at different path than mine!!!

Create the following PHP script in /volume1/web/ :

wol.php

<?php
// outputs the username that owns the running php/httpd process
// // (on a system with the "whoami" executable in the path)
$output=null;
$retval=null;
exec('whoami', $output, $retval);
echo "Returned with status $retval and output:\n";
print_r($output);

$output = "";
exec('python wakeonlan.py 192.168.10.255 FF:85:C2:70:23:8D', $output, $retval);

echo "Calling WAKE-ON-LAN command:";
print_r($output);
?>

So now once you have established VPN connection to your home network via OpenVPN, you have to open your browser and the local page on your Synology like this:

http://your_synoklogy_ip/wol.php

And depending on the speed of your PC (for mine it’s 5-6 seconds) you can use the Remote Desktop as usual to connect to Windows 10 desktop.

Enjoy.