Documentation ¶
Overview ¶
Package wol implements a Wake-on-LAN client.
Index ¶
Constants ¶
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 ¶
NewClient creates a new Client which binds to any available UDP port to send Wake-on-LAN magic packets.
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 ¶
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 ¶
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) 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.