Tool · Windows service
WolCatcher
A Wake-on-LAN app on the phone can turn a PC on but can't turn it off. WolCatcher closes that gap: it's a small Windows service that catches the magic packet while the PC is already on and shuts the PC down. The same WoL button now both wakes and turns off the computer.
It has been running as a service on my own PC since June.
Magic packet · 102 bytes
- UDP 9 · 7listened on, broadcast included
- 45 sstartup grace against the phone's repeat packets
- 3actions: shut down, sleep or hibernate
- 1exe that installs and manages itself as a service
How it works
A .NET Generic Host app that runs as a Windows service.
-
Listen
The service listens on UDP ports 9 and 7, broadcast included. Both ports can be changed in the settings.
-
Find the magic packet anywhere
It scans the whole payload for six 0xFF bytes followed by a MAC address repeated 16 times, so extra bytes at the start or a SecureOn password at the end don't stop the packet from being recognised.
-
Check the MAC
MAC addresses are read from the PC's network adapters automatically, or listed by hand in
appsettings.json. Packets for other machines are ignored. -
Act
Shut down with
shutdown.exe, or sleep and hibernate throughSetSuspendStateinpowrprof.dll, called with P/Invoke. -
Don't overreact
After a WoL boot the phone keeps sending a few more packets, so anything that arrives in the first 45 seconds after the service starts is ignored. A separate cooldown stops repeated triggers in a short window.
for (int i = 0; i <= payload.Length - CoreLen; i++)
{
if (!AllByte(payload.Slice(i, MacLen), 0xFF))
continue;
var mac = payload.Slice(i + MacLen, MacLen);
bool valid = true;
for (int r = 1; r < Repeat; r++)
{
if (!mac.SequenceEqual(payload.Slice(i + MacLen + r * MacLen, MacLen)))
{
valid = false;
break;
}
}
if (valid)
return mac.ToArray();
}
Manages itself
The same exe installs the service with sc.exe, set to start automatically and restart after a crash. When it needs admin rights it relaunches itself through UAC. Logs go to %ProgramData%\WolCatcher\wolcatcher.log, which is moved to .1 once it passes 5 MB; start, stop and error events also appear in Event Viewer.
Commands and settings
Service commands need administrator rights.
| Command | What it does |
|---|---|
install | Installs and starts the service |
uninstall | Stops and removes the service |
start, stop | Starts or stops the service |
status | Shows the service status |
console | Runs in the console instead of as a service |
help | Shows usage |
{
"WolCatcher": {
"Ports": [ 9, 7 ],
"Action": "Shutdown",
"StartupGraceSeconds": 45,
"TargetMacs": [],
"ActionDelaySeconds": 0,
"Force": true,
"CooldownSeconds": 10
}
}
Action:Shutdown,SleeporHibernate.TargetMacs: when empty, the MACs of this PC's adapters are used.AA:BB:CC:DD:EE:FF,aa-bb-cc-dd-ee-ffand plain hex all work.Force: closes open apps when shutting down, so unsaved work can be lost.- Any setting can also come from an environment variable, for example
WolCatcher__Action=Sleep. Restart the service after changingappsettings.json.
Setup
Windows 10/11 x64. Download the release, or build it with the .NET 10 SDK.
-
Get a single-file exe
Download the zip from Releases, or publish it yourself:
PowerShelldotnet publish -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -o publish -
Install the service
Copy
WolCatcher.exeandappsettings.jsonto a permanent folder such asC:\Tools\WolCatcher. The service points at that path, so don't move the folder afterwards.PowerShell.\WolCatcher.exe install -
Set up the network
Turn on Wake-on-LAN in the BIOS/UEFI and the network adapter settings. In the phone app, target the network's broadcast address (for example
192.168.1.255) on port 9. You may need to allow inbound UDP 9 and 7 in Windows Firewall.
Try it without shutting down
Stretch the startup grace and run it in the console; every packet is logged but the PC stays on.
$env:WolCatcher__StartupGraceSeconds = "99999"
dotnet run -- consoleKnown issues
- When the PC wakes from sleep through WoL, the startup grace doesn't apply, because it's only counted when the service starts. The phone's repeat packets can make it try to shut the PC down again right away.
- If an action fails, the trigger lock isn't reset and new packets are ignored until the service restarts. For the same reason, Sleep and Hibernate work only once per service run.
- There's no authentication: any device on the same network that sends a magic packet for this PC's MAC can shut it down.
- Only Information-level logs and above are written to the file.
- Windows only, with no automated tests.