Skip to content

Send magic packet from php to wake up a host using "Wake on Lan"

License

Notifications You must be signed in to change notification settings

AndiSHFR/wake-on-lan.php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 

Repository files navigation

wake-on-lan.php

Send magic packet from php to wake up a host using "Wake on Lan"

Wake-On_Lan Screenshot

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.

Changes of the 2021 Release

  • Now it is really a one file drop in.
  • Version update for bootstrap and jquery.
  • Configuration is now saved to the backend. (Make sure web server can write to it.)
  • Host check is now done via connection test to ssh, rdp, http and https.
  • MAC address can now be typed in using dash (-) or colon (:) - both will work.
  • No longer requires the raw-Sockets feature. All is done via the sockets extension in php.

Requirements

  • PHP5 or PHP7
  • Internet connection for CDN includes (.js, .css)
  • Sockets extension must be enabled
  • Web server must be allowed to write to the file config.json

Installation

  • Either clone the repository or download the zip file
  • Copy the file wake-on-lan.php to a directory on your web server

Note: If you need to copy the file to a remote machine use scp or sftp.

Enabling the php sockets extension

The way the php sockets extension is enabled slidely differes with every php installation.

Here are basic steps for linux users:

  • Go to the directory that contains your php.inifile.
  • Open the file with text editor
  • Search for the line ;extension=sockets
  • Remove the trailing semicolon (;) to enable this feature.
  • Save your php.inifile
  • Reload your webserver configuration.

Setup

Open your favorite browser and navigate to the wake-on-lan.php url. Now you can start adding your the hosts you want to wake.

General Operation

Adding a host

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:

  • Mac-Address - Type the mac address of the host you wish to wake. The values can be separated by a dash (-) or a colon (:) - both will work.
  • IP-Address - Type the ip address of the host. This is required to query the "host up" state and calculate the broadcast address of the magic packet.
  • Subnet Size - type in the subnet size in CIDR notation.

Removing a host

To remove a host simply click on the trashcan icon of the host you want to remove.

Saving the configuration

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.

Tools Dropdown Menu

  • Download Configuration - This will download the config.jsonfile 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.jsonfile 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.

Caveat

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.

License

wake-on-lan.php is published under MIT license.

About

Send magic packet from php to wake up a host using "Wake on Lan"

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages