Send magic packet from php to wake up a host using "Wake on Lan"
wake-on-lan.php
started as a one file drop in tool for waking up computers when they are suspended.
Note: As there where numerous issues using this code, even it worked fine in my environment, at the end of 2021 i decided to refactor the whole thing.
config.json
wake-on-lan.php
to a directory on your web serverNote: If you need to copy the file to a remote machine use scp
or sftp
.
The way the php sockets extension is enabled slidely differes with every php installation.
Here are basic steps for linux users:
php.ini
file.;extension=sockets
php.ini
fileOpen your favorite browser and navigate to the wake-on-lan.php
url.
Now you can start adding your the hosts you want to wake.
To add a host simply fill the edit fields at the bottom of the table and press the blue button with the plus sign.
You need to fill the follwing input fields:
To remove a host simply click on the trashcan icon of the host you want to remove.
You can save the configuration by choosing Tools -> Save COnfiguration.
The configuration will be saved to a json file in the same directory as of wake-on-lan.php
.
The web server needs permission to write to the file. You you may need to adjust folder permission accordingly.
Download Configuration - This will download the config.json
file to your computer.
Export Configuration - open a modal window with the configuration as a json file. Copy the contents of the edit window and save the configuration as a file.
Import Configuration - open a modal window with a text box. Paste your configuration into the text box and click on Import.
Load Configuration - Load the configuration from the config.json
file from the web server.
Save Configuration - Save the configuration to the file config.json
on the web server. Make sure the web server process is allowed to write to the file.
Wake up! - send a magic packet for the selected host.
Remove - delete the row from the configuration. The data of the deleted row is placed in the input fields for adding a new host. If you accidently removed a host you can simply press Add again to add it again.
Add - adds a new entry to the table. Fill in the text boxes and press Add.
Does not run under linux. Because the linux user used to run php code on the server side usually has very limited permission it cannot create the raw socket to send the magic packet.
Note: This caveat no longer applies. Using the sockets extension wake-on-lan.php
no longer suffers this shortcoming.
wake-on-lan.php
is published under MIT license.