Skip to content

bavix/sol

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SoL - Shutdown on LAN

SoL is a service that listens for Wake-on-LAN magic packets and triggers power actions (shutdown or reboot) when received.

Inspiration

This project was inspired by the article "Выключаем компьютер через Wake-on-Lan" on Habr, which demonstrates how to repurpose Wake-on-LAN packets for shutdown functionality instead of wake-up.

Description

The sol service is built using cobra CLI framework and Go standard library.

Listen

The listen command listens for Wake-on-LAN magic packets on the specified network interface and triggers a power action when a matching packet is received.

Protocol

The service listens for Wake-on-LAN magic packets on UDP ports. When a magic packet containing the target MAC address is received, the configured power action is executed.

Supported Actions

  • shutdown — shut down the system (shutdown -h now on Linux/macOS, shutdown -s -t 0 -f on Windows)
  • reboot — restart the system (shutdown -r now on Linux/macOS, shutdown -r -t 0 -f on Windows)

Run the service

Simple mode

sol listen --iface eth0 --port 9

Advanced mode (multiple ports)

Listen on multiple ports with different actions:

sol listen --iface eth0 --port 9 --port 8:reboot

Options

  • --iface: Network interface name to bind to (required)
  • --port: UDP port to listen on, optionally with action (e.g. 9 for shutdown, 8:reboot for specific action). Can be specified multiple times
  • --dry-run: Log when a matching packet is received instead of executing the power action

Installation

Quick Install

Download the latest release for your platform and architecture:

Linux AMD64:

curl -L https://github.com/bavix/sol/releases/download/v0.0.2/sol-v0.0.2-linux-amd64.tar.gz | tar -xz && sudo mv sol /usr/local/bin/

Linux ARM64:

curl -L https://github.com/bavix/sol/releases/download/v0.0.2/sol-v0.0.2-linux-arm64.tar.gz | tar -xz && sudo mv sol /usr/local/bin/

macOS Intel:

curl -L https://github.com/bavix/sol/releases/download/v0.0.2/sol-v0.0.2-darwin-amd64.tar.gz | tar -xz && sudo mv sol /usr/local/bin/

macOS Apple Silicon:

curl -L https://github.com/bavix/sol/releases/download/v0.0.2/sol-v0.0.2-darwin-arm64.tar.gz | tar -xz && sudo mv sol /usr/local/bin/

Windows (PowerShell):

Invoke-WebRequest -Uri "https://github.com/bavix/sol/releases/download/v0.0.2/sol-v0.0.2-windows-amd64.zip" -OutFile "sol.zip"
Expand-Archive -Path "sol.zip" -DestinationPath "." -Force
move sol.exe C:\Windows\System32\sol.exe

Verify Installation

sol --help

Systemd Service Setup

To run SoL as a systemd service that starts automatically:

  1. Create systemd unit file

    sudo nano /etc/systemd/system/sol.service

    Add the following content:

    [Unit]
    Description=SOL listener
    After=network-online.target
    Wants=network-online.target
    
    [Service]
    ExecStart=/usr/local/bin/sol listen --iface enp2s0 --port 9 --port 8:reboot
    Restart=always
    RestartSec=5
    User=root
    
    [Install]
    WantedBy=multi-user.target

    Important: Replace enp2s0 with your actual network interface name.

  2. Reload systemd configuration

    sudo systemctl daemon-reload
  3. Enable autostart

    sudo systemctl enable sol.service
  4. Start the service

    sudo systemctl start sol.service
  5. Check service status

    sudo systemctl status sol.service
  6. View logs

    journalctl -u sol.service -f

Service Configuration Notes

  • After=network-online.target ensures the service starts after the network is fully online
  • Restart=always automatically restarts the service if it crashes
  • For production use, remove --dry-run flag from the ExecStart command
  • Consider creating a dedicated user instead of running as root for better security
  • When using multiple ports, separate them with multiple --port flags

Security Note

Any device on the same network segment can send Wake-on-LAN magic packets. This means any device that can reach the listening ports can trigger shutdown or reboot. Use firewall rules or network segmentation to restrict access.

About

Shutdown on LAN - reverse Wake-on-LAN implementation in Go

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors