wol

package module
v0.0.0-...-a07ae2b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 6 Imported by: 0

README

wol builds.sr.ht status GoDoc Go Report Card

Package wol implements a Wake-on-LAN client. MIT Licensed.

This package exposes two types, which operate slightly differently:

  • Client: WoL client which uses UDP sockets to send magic packets
  • RawClient WoL client which uses raw Ethernet sockets to send magic packets

For most use cases, the Client type will be sufficient. The RawClient type requires elevated privileges (root user) and works on Linux or *BSD/macOS only.

Documentation

Overview

Package wol implements a Wake-on-LAN client.

Index

Constants

View Source
const (
	// EtherType is the registered EtherType for Wake-on-LAN over Ethernet.
	// See: https://wiki.wireshark.org/WakeOnLAN.
	EtherType = 0x0842
)

Variables

This section is empty.

Functions

This section is empty.

Types

type MagicPacket

type MagicPacket struct {
	// Target specifies the hardware address of a LAN device to wake using
	// this MagicPacket.
	Target net.HardwareAddr

	// Password specifies an optional password for this MagicPacket.  Password
	// must be exactly 0 (empty), 4, or 6 bytes in length.
	Password []byte
}

A MagicPacket is a Wake-on-LAN packet. It specifies a target hardware address to wake, and optionally, a password used to authenticate the MagicPacket wake request.

func (*MagicPacket) MarshalBinary

func (p *MagicPacket) MarshalBinary() ([]byte, error)

MarshalBinary allocates a byte slice and marshals a MagicPacket into binary form.

If p.Target is not exactly 6 bytes in length, errInvalidTarget is returned.

If p.Password is not exactly 0 (empty), 4, or 6 bytes in length, errInvalidPassword is returned.

func (*MagicPacket) UnmarshalBinary

func (p *MagicPacket) UnmarshalBinary(b []byte) error

UnmarshalBinary unmarshals a byte slice into a MagicPacket.

If the byte slice does not contain enough data to unmarshal a valid MagicPacket, io.ErrUnexpectedEOF is returned.

type RawClient

type RawClient struct {
	// contains filtered or unexported fields
}

A RawClient is a Wake-on-LAN client which operates directly on top of Ethernet frames using Ethernet sockets. It can be used to send WoL magic packets to other machines on a local network, using their hardware addresses.

func NewRawClient

func NewRawClient(ifi *net.Interface) (*RawClient, error)

NewRawClient creates a new RawClient using the specified network interface.

Note that Ethernet sockets typically require elevated user privileges, such as the 'root' user on Linux, or the 'SET_CAP_RAW' capability.

For this reason, it is typically recommended to use the regular Client type instead, which operates over UDP.

func (*RawClient) Close

func (c *RawClient) Close() error

Close closes a RawClient's socket.

func (*RawClient) Wake

func (c *RawClient) Wake(target net.HardwareAddr) error

Wake sends a Wake-on-LAN magic packet to the specified hardware address.

func (*RawClient) WakePassword

func (c *RawClient) WakePassword(target net.HardwareAddr, password []byte) error

WakePassword sends a Wake-on-LAN magic packet to the specified hardware address, using the specified Password.

The password must be exactly 0 (empty), 4, or 6 bytes in length.

Directories

Path Synopsis
cmd
wol command
Command wol is a simple Wake-on-LAN client.
Command wol is a simple Wake-on-LAN client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL