I recently stopped running a webserver at home, and started using a hosted service instead. This was prompted by the realisation that even with my PC on only during the day, it was still costing more to run per year than a 24/7 service elsewhere.

However, it is still sometimes useful to have my home PC on for remote access to its systems

The solution was WoL (Wake On Lan), or in my Case WoW (Wake on Wan). This works by sending a small packet ('magic' packet) to your PC telling it to wake up. Most motherboards have some power to them even when off (to power the clock etc) and this allows the network card to sniff packets. If you have set WoL up in the BIOS, then it will boot up the PC.

This WoL solution consists of three files:

Magic packet structure:

ff ff ff ff ff ff Followed by 16 copies of the MAC address of the NIC on the pc you want to wake up.

FF FF FF FF FF FF
pc mac address
pc mac address
....
...
.

When sending this packet, we have to be carefult that we send the correct data. For example, our mac addresses are specified as 6 hex codes. But if we send these as a string, what we are sending is the ASCII codes for those characters, not the values those characters represent! This is no good - we must therefore find the ascii characters to which our desired values match when creating our message string. That way we can be sure we are sending the correct info

As a solution, I wrote a little php/javascript page that takes as input a URL and a port. It then extracts the domain or IP address from the URL ans sends a WoL packet to the specified port and location using an ajax call.

It returns from the ajax call either when the ping times out (user definable) or when the ping is succesful. If succesful, the user is then redirected to his originally specified URL. The files are shown below. The php file is the only one that needs changing (to set neccesary details for your system), and is well commented.

One thing to note is that for this to work across the internet, you will probably have to set up a static route on your router. Most routers periodically poll their LAN and wipe the ARP table entries for hosts that have not responded after a few minutes. If this happens, there is no way of your wake up packet reaching your PC, since the router no longer knows its MAC address.

A static route sets up a permanent ARP record valid even when the PC is off.

You will need to ensure that the server you host these files on lets you open and listen on an created sockets (for sending your wake up packet and pinging the server for a response) - my new host did not, but since the utility is so small I was able to find somewhere else to keep it available.