Wake-on-LAN from a Windows machine
Posted by jpluimers on 2022/06/02
Before digging into Wake-on-LAN on Windows machines, I’ll interlude with basically the canonical wakonlan
available on many non Windows machines
On Linux and BSD machines, there is the Perl script wakeonlan (steadily at version 0.41) at [Wayback/Archive.is] jpoliv/wakeonlan: Perl script for waking up computers via Wake-On-LAN magic packets (script: [Wayback/Archive.is] wakeonlan/wakeonlan at master · jpoliv/wakeonlan) with this help:
/usr/local/bin/wakeonlan version 0.41 calling Getopt::Std::getopts (version 1.07 [paranoid]), running under Perl version 5.18.2. Usage: wakeonlan [-OPTIONS [-MORE_OPTIONS]] [--] [PROGRAM_ARG1 ...] The following single-character options are accepted: With arguments: -p -i -f Boolean (without arguments): -h -v Options may be merged together. -- stops processing of options. Space is not required between options and their arguments. For more details run perldoc -F /usr/local/bin/wakeonlan [Now continuing due to backward compatibility and excessive paranoia. See 'perldoc Getopt::Std' about $Getopt::Std::STANDARD_HELP_VERSION.] Usage wakeonlan [-h] [-v] [-i IP_address] [-p port] [-f file] [[hardware_address] ...] Options -h this information -v displays the script version -i ip_address set the destination IP address default: 255.255.255.255 (the limited broadcast address) -p port set the destination port default: 9 (the discard port) -f file uses file as a source of hardware addresses See also wakeonlan(1)
Looking at the source code:
- it defaults to udp port 9 (the
discard
port, see [Wayback/Archive.is] Service Name and Transport Protocol Port Number Registry:discard
) - it should support these formats for MAC addresses (the
hardware_address
part of the parameters):xx:xx:xx:xx:xx:xx
(canonical)xx-xx-xx-xx-xx-xx
(Windows)xxxxxx-xxxxxx
(Hewlett-Packard switches)xxxxxxxxxxxx
(Intel Landesk)
Note there is also a notation for using dots, see MAC address: Notational conventions – Wikipedia
The standard (IEEE 802) format for printing EUI-48 addresses in human-friendly form is six groups of two hexadecimal digits, separated by hyphens (
-
) in transmission order (e.g.01-23-45-67-89-AB
). This form is also commonly used for EUI-64 (e.g.01-23-45-67-89-AB-CD-EF
).[2] Other conventions include six groups of two hexadecimal digits separated by colons (:) (e.g.01:23:45:67:89:AB
), and three groups of four hexadecimal digits separated by dots (.) (e.g.0123.4567.89AB
); again in transmission order.[30]
A problem is that almost no distribution uses the latest code from github which works:
# ./wakeonlan -v wakeonlan 0.41_90 # ./wakeonlan d4-3d-7e-b7-30-d6 Illegal hexadecimal digit '-' ignored at ./wakeonlan line 164. Sending magic packet to 255.255.255.255:9 with payload d4-3d-7e-b7-30-d6 Hardware addresses: <total=1, valid=1, invalid=0> Magic packets: <sent=1> # ./wakeonlan -n d4-3d-7e-b7-30-d6 Illegal hexadecimal digit '-' ignored at ./wakeonlan line 164. Sending magic packet to 255.255.255.255:9 with payload d4-3d-7e-b7-30-d6 Hardware addresses: <total=1, valid=1, invalid=0> Magic packets: <sent=1> # ./wakeonlan -n d43d7e-b730d6 Illegal hexadecimal digit '-' ignored at ./wakeonlan line 164. Sending magic packet to 255.255.255.255:9 with payload d43d7e-b730d6 Hardware addresses: <total=1, valid=1, invalid=0> Magic packets: <sent=1> # ./wakeonlan -n d43d7eb730d6 Hexadecimal number > 0xffffffff non-portable at ./wakeonlan line 164. Sending magic packet to 255.255.255.255:9 with payload d43d7eb730d6 Hardware addresses: <total=1, valid=1, invalid=0> Magic packets: <sent=1> # ./wakeonlan -n d4:3d:7e:b7:30:d6 Sending magic packet to 255.255.255.255:9 with payload d4:3d:7e:b7:30:d6 Hardware addresses: <total=1, valid=1, invalid=0> Magic packets: <sent=1>
It fails for instance on MacOS with [Wayback] homebrew installed wakeonlan:
# wakeonlan -v wakeonlan version 0.41 # wakeonlan d4-3d-7e-b7-30-d6 Invalid hardware address: d4-3d-7e-b7-30-d6 # wakeonlan d43d7e-b730d6 Invalid hardware address: d43d7e-b730d6 # wakeonlan d43d7eb730d6 Invalid hardware address: d43d7eb730d6 # wakeonlan d4:3d:7e:b7:30:d6 Sending magic packet to 255.255.255.255:9 with d4:3d:7e:b7:30:d6
That uses this [Wayback] install script which downloads the latest from the [Wayback] releases, which is exactly version 0.41
, not the current working version 0.41_90
.
This sets a baseline for what I’m looking for in a Windows version of wakeonlan:
- support at least
discard
port 9 - support at least canonical, but preferably also Windows formatted hardware MAC addresses, and not displaying warnings for otherwise valid hardware MAC addresses
Documentation related to Wake on LAN
Before searching for that, I dug up some of the documentation, partially through the [Wayback] wakeonlan README.md file:
- Wake-on-LAN – Wikipedia, especially these bits:
The magic packet is a frame that is most often sent as a broadcast and that contains 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 could be sent as payload of any network- and transport-layer protocol, although it is typically sent as a UDP datagram to port 0 (reserved port number),[6] 7 (Echo Protocol) or 9 (Discard Protocol),[7] or directly over Ethernet as EtherType
0x0842
.[8] A connection-oriented transport-layer protocol like TCP is less suited for this task as it requires establishing an active connection before sending user data.A standard magic packet has the following basic limitations:
- Requires destination computer MAC address (also may require a SecureOn password)
- Does not provide a delivery confirmation
- May not work outside of the local network
- Requires hardware support of Wake-on-LAN on destination computer
- 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, IP addresses and DNS names are meaningless and so the MAC address is required.
- Discard Protocol – Wikipedia on port
9
(back then only fortcp
andudp
, but by now also forsctp
anddccp
, though only udp is used for Wake-on-LAN) - Echo Protocol – Wikipedia on port
7
(only fortcp
andudp
) - [Wayback] WakeOnLAN · Wiki · Wireshark Foundation / wireshark · GitLab
Protocol dependencies
- Ethernet: According to AMD’s white paper, WakeOnLAN depends only on Ethernet. However, the paper also indicates that the Magic Packet can reside anywhere within the payload. This means that we would have to search every Ethernet frame for the Magic Packet. In my opinion, doing so would degrade Wireshark performance, especially since most traffic will not contain a Magic Packet. Therefore, the WakeOnLAN dissector has been implemented to dissect only the actual implementations of the Magic Packet. As of this writing, the author is only aware of 2 implementations, one being ether-wake which uses Ethertype
0x0842
, which is unfortunately not yet a registered Ethertype, and the other implementation being over UDP. - UDP: Several tools mentioned in the above wikipedia article implement the Magic Packet over UDP.
Packet Format
A physical WakeOnLAN (Magic Packet) will look like this:
Synchronization Stream Target MAC Password (optional) 6 96 0, 4 or 6 The Synchronization Stream is defined as 6 bytes of FFh.
The Target MAC block contains 16 duplications of the IEEE address of the target, with no breaks or interruptions.
The Password field is optional, but if present, contains either 4 bytes or 6 bytes. The WakeOnLAN dissector was implemented to dissect the password, if present, according to the command-line format that ether-wake uses, therefore, if a 4-byte password is present, it will be dissected as an IPv4 address and if a 6-byte password is present, it will be dissected as an Ethernet address.
- Ethernet: According to AMD’s white paper, WakeOnLAN depends only on Ethernet. However, the paper also indicates that the Magic Packet can reside anywhere within the payload. This means that we would have to search every Ethernet frame for the Magic Packet. In my opinion, doing so would degrade Wireshark performance, especially since most traffic will not contain a Magic Packet. Therefore, the WakeOnLAN dissector has been implemented to dissect only the actual implementations of the Magic Packet. As of this writing, the author is only aware of 2 implementations, one being ether-wake which uses Ethertype
- [Wayback] ether-wake(8): send Wake-On-LAN Magic Packet – Linux man page
In practice, it seems no tools uses a different UDP port than 9 (discard
protocol).
Windows Wake-on-LAN tools
It is tough to find Windows Wake-on-LAN tools that are open source. The first few on the list are closed source.
- [Wayback] Chocolatey Software | WakeMeOnLan 1.87 which is the installer for Nirsoft’s [Wayback] WakeMeOnLan – Turn on computers on your network with Wake-on-LAN packet having [Wayback]
WakeMeOnLan.exe
.- I wrote this little
wakeonlan.bat
batch file for it:
:: depends on Nirsoft's WakeMeOnLan: https://www.nirsoft.net/utils/wake_on_lan.html :: see choco-install-wakeonlan.bat WakeMeOnLan /wakeup %*
- It works with all the hardware MAC address formats above:
c:\temp> wakeonlan d4-3d-7e-b7-30-d6
WakeMeOnLan /wakeup d4-3d-7e-b7-30-d6
c:\temp> wakeonlan d43d7e-b730d6
WakeMeOnLan /wakeup d43d7e-b730d6
c:\temp> wakeonlan d43d7eb730d6
WakeMeOnLan /wakeup d43d7eb730d6
c:\temp> wakeonlan d4:3d:7e:b7:30:d6
WakeMeOnLan /wakeup d4:3d:7e:b7:30:d6
- I wrote this little
- [Wayback/Archive.is] Welcome To Depicus – Home of the Geek has [Wayback]
WolCmd.exe
, defaults to port 7 (echo
) and requires way too many parameters as these all show the same help:
C:\>WolCmd.exe d4-3d-7e-b7-30-d6 C:\>WolCmd.exe d43d7e-b730d6 C:\>WolCmd.exe d43d7eb730d6 C:\>WolCmd.exe d4:3d:7e:b7:30:d6 C:\>WolCmd.exe --help Wake On Lan Command Line... Usage: wolcmd [mac address] [ipaddress] [subnet mask] [port number] i.e. wolcmd 009027a322fc 195.188.159.20 255.255.255.0 7 or wolcmd 009027a322fc depicus.com 255.255.255.0 7 Copyright www.depicus.com (Brian Slack) 1966-2005
It is Delphi based (my guess is even Delphi 7 based) and seems based on [Wayback/Archive.is] wake-on-lan-for-windows-3.1/WOL.PAS at master · Depicus/wake-on-lan-for-windows-3.1.
- [Wayback] Gammadyne’s Free DOS Utilities:
WOL.EXE
has [Wayback]WOL.EXE
, which is written in C++, uses port 9 (discard
) and runs with any hardware MAC address format I tried:
C:\>wol.exe d4-3d-7e-b7-30-d6 C:\>wol.exe d43d7e-b730d6 C:\>wol.exe d43d7eb730d6 C:\>wol.exe d4:3d:7e:b7:30:d6
all show this:
WOL.exe 2.1 - Wake-On-LAN Utility - www.Gammadyne.com Copyright (C) 2000-2017 by Greg Wittmeyer - All Rights Reserved Wake-up packet sent successfully.
The help from
wol.exe --help
is this:WOL.exe 2.1 - Wake-On-LAN Utility - www.Gammadyne.com Copyright (C) 2000-2017 by Greg Wittmeyer - All Rights Reserved Invalid argument: --help Usage: wol.exe mac_address [adapter_ip] [port] [/pwd password] [/d subnet] Example: wol.exe 3c7f45d9e56a Example: wol.exe 7A-2C-74-EE-19-F3 192.168.0.1 Example: wol.exe f1:dc:84:e6:2a:c9 192.168.0.1 12287 Example: wol.exe 7363be847f12 9 /pwd sesame Example: wol.exe 45F7BA186E4D /pwd 16a34d28f4c3 Example: wol.exe E682B634D7A6 /pwd 2A:E3:64:DD:59:3F Example: wol.exe 13-A4-99-1F-C4-8E /d 192.168.2.255
This was a good second to NirSoft’s
WakeMeOnLan.exe
, basically because the latter is easier to upgrade through chocolatey.
A few open source Powershell scripts, some of which are very dense (something I don’t like as it makes understanding these scripts extremely hard for novices):
- [Archive.is] Wayback: Script Send WOL packet using Powershell which had (as Technet Gallery vanished) Wayback:
Send-WOL.ps1
, a very dense script only having a functionSend-WOL
, so no command-line parsing at all. - [Wayback] PowerShell Gallery | WakeOnLan 1.0 has a [Wayback]
WakeOnLan
module. Inside is also a function, now namedInvoke-WakeOnLan
, less dense thanSend-WOL
. - [Wayback] Wake On LAN – powershell.one also has a function
Invoke-WakeOnLan
, and looks remarkably the same as the PowerShell Gallery script above. - [Wayback/Archive.is] PowerShell script for sending Wake On LAN magic packets to given machines/MAC address(es) has [Wayback/Archive.is]
Wake.ps1
that parses command-line parameters so it can wake up a single host.- It is a modification (see [Wayback] revision history) of [Wayback]
WakeUp-Machines.ps1
by [Archive.is] Matthijs ten Seldam, Microsoft that has the drawback of requiring a text file with the machines to wake up, and (before his change) the reliance on the above mentionedWolCmd.exe
in the current directory. - It can handle just the Windows and Hewlett-Packard switches styles of the hardware MAC address formats:
C:\>powershell -file Wake.ps1 d4-3d-7e-b7-30-d6 Sending magic packet to d4-3d-7e-b7-30-d6 C:\>powershell -file Wake.ps1 d43d7e-b730d6 Sending magic packet to d43d7e-b730d6 Send-Packet : Exception calling "Parse" with "1" argument(s): "An invalid physical address was specified." At C:\\Wake.ps1:82 char:1 + Send-Packet $MacAddress + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Send-Packet An error occurred while enumerating through a collection: Collection was modified; enumeration operation may not execute.. At C:\\Wake.ps1:76 char:9 + $Error | Write-Error; + ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Collecti...numeratorSimple:ArrayListEnumeratorSimple) [], R untimeException + FullyQualifiedErrorId : BadEnumeration C:\>powershell -file Wake.ps1 d43d7eb730d6 Sending magic packet to d43d7eb730d6 C:\>powershell -file Wake.ps1 d4:3d:7e:b7:30:d6 Sending magic packet to d4:3d:7e:b7:30:d6 Send-Packet : Exception calling "Parse" with "1" argument(s): "An invalid physical address was specified." At C:\\Wake.ps1:82 char:1 + Send-Packet $MacAddress + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Send-Packet An error occurred while enumerating through a collection: Collection was modified; enumeration operation may not execute.. At C:\\Wake.ps1:76 char:9 + $Error | Write-Error; + ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Collecti...numeratorSimple:ArrayListEnumeratorSimple) [], R untimeException + FullyQualifiedErrorId : BadEnumeration
It also omits help text:
C:\>powershell -file Wake.ps1 --help C:\\Wake.ps1 : A parameter cannot be found that matches parameter name '-help'. + CategoryInfo : InvalidArgument: (:) [Wake.ps1], ParentContainsErrorRecordException + FullyQualifiedErrorId : NamedParameterNotFound,Wake.ps1 C:\>powershell -file Wake.ps1 -help C:\\Wake.ps1 : A parameter cannot be found that matches parameter name 'help'. + CategoryInfo : InvalidArgument: (:) [Wake.ps1], ParentContainsErrorRecordException + FullyQualifiedErrorId : NamedParameterNotFound,Wake.ps1
- It is a modification (see [Wayback] revision history) of [Wayback]
- inte explains some of the magic (especially the byte-array initialisation magic and a trick splitting on both
:
and-
delimiters) that most of these PowerShell scripts use parts of.
Conclusion
There are open source Wake-on-LAN tools available for Windows, but none of them as versatile as the closed source tools or the wakeonlan
Perl script above.
–jeroen
Leave a Reply