Wake-on-LAN (WoL) is an Ethernet or token ring computer networking standard that allows a computer to be turned on or awakened by a network message.

  • The message is usually sent to the target computer by a program executed on a device connected to the same local area network, such as a smartphone.
  • It is also possible to initiate the message from another network by using subnet directed broadcasts or a WOL gateway service.
  • Equivalent terms include wake on WAN, remote wake-up, power on by LAN, power up by LAN, resume by LAN, resume on LAN and wake up on LAN.

Principle of operation

  • Wake-on-LAN (“WOL”) is implemented using a specially designed packet called a magic packet, which is sent to all computers in a network, among them the computer to be awakened.
  • The magic packet contains the MAC address of the destination computer, an identifying number built into each network interface card (“NIC”) or other ethernet device in a computer, that enables it to be uniquely recognized and addressed on a network.
  • Powered-down or turned off computers capable of Wake-on-LAN will contain network devices able to “listen” to incoming packets in low-power mode while the system is powered down.
  • If a magic packet is received that is directed to the device’s MAC address, the NIC signals the computer’s power supply or motherboard to initiate system wake-up, much in the same way as pressing the power button would do.
  • The magic packet is sent on the data link layer (layer 2 in the OSI model) and when sent, is broadcast to all attached devices on a given network, using the network broadcast address; the IP-address (layer 3 in the OSI model) is not used.[ad type=”banner”]

In order for Wake-on-LAN to work, parts of the network interface need to stay on. This consumes a small amount of standby power, much less than normal operating power. Disabling wake-on-LAN when not needed, can therefore very slightly reduce power consumption on computers that are switched off but still plugged into a power socket.

Magic Packet Structure
The magic packet is a broadcast frame containing anywhere within its payload 6 bytes of all 255 (FF FF FF FF FF FF in hexadecimal), followed by sixteen repetitions of the target computer’s 48-bit MAC address, for a total of 102 bytes.
Since the magic packet is only scanned for the string above, and not actually parsed by a full protocol stack, it may be sent as any network- and transport-layer protocol, although it is typically sent as a UDP datagram to port 0, 7 or 9, or directly over Ethernet as EtherType 0x0842.

A standard magic packet has the following basic limitations:

  1. Requires destination computer MAC address (also may require a SecureOn password).
  2. Does not provide a delivery confirmation.
  3. May not work outside of the local network.
  4. Requires hardware support of Wake-On-LAN on destination computer.
  5. Most 802.11 wireless interfaces do not maintain a link in low power states and cannot receive a magic packet.

The Wake-on-LAN implementation is designed to be very simple and to be quickly processed by the circuitry present on the network interface card with minimal power requirement. Because Wake-on-LAN operates below the IP protocol layer the MAC address is required and makes IP addresses and DNS names meaningless.[ad type=”banner”]

 C programming:
[pastacode lang=”c” manual=”%2F%2F%20C%20program%20to%20remotely%20Power%20On%20a%20PC%20over%20the%0A%2F%2F%20internet%20using%20the%20Wake-on-LAN%20protocol.%0A%23include%20%3Cstdio.h%3E%0A%23include%20%3Cstdlib.h%3E%0A%23include%20%3Cunistd.h%3E%0A%23include%20%3Csys%2Fsocket.h%3E%0A%23include%20%3Cnetinet%2Fin.h%3E%0A%23include%20%3Carpa%2Finet.h%3E%0A%23include%20%3Cstring.h%3E%0A%23include%20%3Csys%2Ftypes.h%3E%0A%20%0Aint%20main()%0A%7B%0A%20%20%20%20int%20i%3B%0A%20%20%20%20unsigned%20char%20toSend%5B102%5D%2Cmac%5B6%5D%3B%0A%20%20%20%20struct%20sockaddr_in%20udpClient%2C%20udpServer%3B%0A%20%20%20%20int%20broadcast%20%3D%201%20%3B%0A%20%0A%20%20%20%20%2F%2F%20UDP%20Socket%20creation%0A%20%20%20%20int%20udpSocket%20%3D%20socket(AF_INET%2C%20SOCK_DGRAM%2C%200)%3B%0A%20%0A%20%20%20%20%2F%2F%20Manipulating%20the%20Socket%0A%20%20%20%20if%20(setsockopt(udpSocket%2C%20SOL_SOCKET%2C%20SO_BROADCAST%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%26broadcast%2C%20sizeof%20broadcast)%20%3D%3D%20-1)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20perror(%22setsockopt%20(SO_BROADCAST)%22)%3B%0A%20%20%20%20%20%20%20%20exit(EXIT_FAILURE)%3B%0A%20%20%20%20%7D%0A%20%20%20%20udpClient.sin_family%20%3D%20AF_INET%3B%0A%20%20%20%20udpClient.sin_addr.s_addr%20%3D%20INADDR_ANY%3B%0A%20%20%20%20udpClient.sin_port%20%3D%200%3B%0A%20%0A%20%20%20%20%2F%2FBinding%20the%20socket%0A%20%20%20%20bind(udpSocket%2C%20(struct%20sockaddr*)%26udpClient%2C%20sizeof(udpClient))%3B%0A%20%0A%20%20%20%20for%20(i%3D0%3B%20i%3C6%3B%20i%2B%2B)%0A%20%20%20%20%20%20%20%20toSend%5Bi%5D%20%3D%200xFF%3B%0A%20%0A%20%20%20%20%2F%2F%20Let%20the%20MAC%20Address%20be%20ab%3Acd%3Aef%3Agh%3Aij%3Akl%0A%20%20%20%20mac%5B0%5D%20%3D%200xab%3B%20%20%2F%2F%201st%20octet%20of%20the%20MAC%20Address%0A%20%20%20%20mac%5B1%5D%20%3D%200xcd%3B%20%20%2F%2F%202nd%20octet%20of%20the%20MAC%20Address%0A%20%20%20%20mac%5B2%5D%20%3D%200xef%3B%20%20%2F%2F%203rd%20octet%20of%20the%20MAC%20Address%0A%20%20%20%20mac%5B3%5D%20%3D%200xgh%3B%20%20%2F%2F%204th%20octet%20of%20the%20MAC%20Address%0A%20%20%20%20mac%5B4%5D%20%3D%200xij%3B%20%20%2F%2F%205th%20octet%20of%20the%20MAC%20Address%0A%20%20%20%20mac%5B5%5D%20%3D%200xkl%3B%20%20%2F%2F%206th%20octet%20of%20the%20MAC%20Address%0A%20%0A%20%20%20%20for%20(i%3D1%3B%20i%3C%3D16%3B%20i%2B%2B)%0A%20%20%20%20%20%20%20%20memcpy(%26toSend%5Bi*6%5D%2C%20%26mac%2C%206*sizeof(unsigned%20char))%3B%0A%20%0A%20%20%20%20udpServer.sin_family%20%3D%20AF_INET%3B%0A%20%0A%20%20%20%20%2F%2F%20Braodcast%20address%0A%20%20%20%20udpServer.sin_addr.s_addr%20%3D%20inet_addr(%2210.89.255.255%22)%3B%0A%20%20%20%20udpServer.sin_port%20%3D%20htons(9)%3B%0A%20%0A%20%20%20%20sendto(udpSocket%2C%20%26toSend%2C%20sizeof(unsigned%20char)%20*%20102%2C%200%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20(struct%20sockaddr*)%26udpServer%2C%20sizeof(udpServer))%3B%0A%20%20%20%20return%200%3B%0A%7D” message=”” highlight=”” provider=”manual”/]

Output:

This program will power on the switched-off PC
whose MAC Address is used in this program (the 
PC and the Host computer must be connected over
LAN).
[ad type=”banner”]