wol

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

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

Go to latest
Published: Feb 21, 2022 License: MIT Imports: 6 Imported by: 8

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 Client

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

A Client is a Wake-on-LAN client which utilizes a UDP socket. It can be used to send WoL magic packets to other machines using their network address.

func NewClient

func NewClient() (*Client, error)

NewClient creates a new Client which binds to any available UDP port to send Wake-on-LAN magic packets.

func (*Client) Close

func (c *Client) Close() error

Close closes a Client's UDP socket.

func (*Client) Wake

func (c *Client) Wake(addr string, target net.HardwareAddr) error

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

Note that Wake sends an IP packet, and powered-down network devices generally don't listen on IP addresses. In most cases, addr should be the broadcast address of a subnet configured on the VLAN the target machine is connected to (eg. 10.0.0.255/24). This uses the OS' routing table to select an outgoing interface to send an Ethernet broadcast on.

However, IPv6 doesn't have subnet-directed broadcasts. The contents of addr are passed to net.Dial, but be aware that sending to multicast addresses like ff02::1 triggers NDP solicitations before sending the packet, which a powered-down device will usually not reply to. Linux seems to refuse to send IPv6 packets at all to Ethernet address ffff.ffff.ffff, not even when explicitly added as a neighbour entry.

If there is no IPv4 subnet available on your target VLAN, add a small dummy subnet or use a RawClient for sending raw Ethernet frames.

func (*Client) WakePassword

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

WakePassword sends a Wake-on-LAN magic packet to an IP address for the specified hardware address, using the specified password.

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

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 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