I use this script to wake up my home servers remotely from internet. I say servers but it can be used for anything really - desktop computers / laptops.
I usually have a subdomain for each of my servers like: wol.server1.domain.com which hosts the script. Everytime I hit the subdomain target server wakes up. This setup is quite flexible as you can put to sleep your servers and wake them up anytime, from anywhere in the world, with any device that has a browser!
- Target computer should have motherboard that supports wake on lan (magic packets). And it should be enabled, both in BIOS and OS. For ubuntu this is an excellent doc: https://help.ubuntu.com/community/WakeOnLan
- Don't forget to open correct ports, sending machine, target machine and on router.
- Upload index.php and wow.class.php onto your sending server. You can use any shared hosting provider, but note that most of them will not open ports below 1000 for you. So choose something 1000 like 1007 for example.
- Edit index.php - line 5
$WoW = new WoW("wow.example.com","xx:xx:xx:xx:xx:xx","xxxx");
- WoW accepts a. hostname, b. mac address, c. port number. and optional d. ip address. If d is not provided script automatically gets ip from hostname.
- Lets use port 1007 as an example.
- Open outgoing port 1007 on sending server.
- On target machines network router:
- Add following forwarder: UDP, from 1007 to 7, ip 192.168.1.254
- 192.168.1.254 this IP shouldn't belong to any device. It is a free IP address we will use for an ARP entry later
- 1007 is the outoing port we opened on sending machine.
- 7 is the port my motherboard uses for wake on lan packages. Check manual for yours!
- We will need to add ARP entry in the router:
arp -i br0 -s 192.168.1.254 FF:FF:FF:FF:FF:FF
- Add following forwarder: UDP, from 1007 to 7, ip 192.168.1.254
So in nutshell it works like this:
- Script sends magic packet to target computers router
- Router forwards port from 1007 to 7 and to IP address 192.168.1.254
- 192.168.1.254 has ARP entry FF:FF:FF:FF:FF:FF which means broadcast to network
- Message is broadcasted in the network on port 7.
- Sleeping/Powered off computer has NIC still powered on, and receives wake on lan message on port 7.
- System wakes up.
#Enjoy!