go-wol

用于 golang 的简单局域网唤醒 Magic Packet 生成器。「Simple wake on LAN magic packet generator for golang」

  • 所有者: sabhiram/go-wol
  • 平台: Linux,Mac,Windows
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

go-wol

Build Status Coverage Status Go Report Card

Wake on LAN magic packet generator for golang.

WOL in the world?

Wake-on-LAN (WOL) describes a simple data link layer protocol which tells a listening ethernet interface to power the target machine up.

Each target system typically exposes a setting in its BIOS which enables or disables the system's WOL capabilities (since this can slowly consume a small amount of standby power).

If you are looking for a tepid overview of the core components of this project in the form of a blog post: see here

Magic Packets (of what?)

The listening interface just looks for a Magic Packet with its MAC address encoded in the WOL scheme. The packet is basically 6 bytes of 0xFF followed by 16 repetitions of the destination interface's MAC address (102 bytes total). The Magic Packet does not have to be exactly 102 bytes, but its relevant payload is. This payload can be sandwiched anywhere in the broadcasts payload.

It's important to remember that since this is typically sent over the data link layer, the target machine's IP address is irrelevant.

Installation

go get github.com/sabhiram/go-wol/cmd/wol
wol wake 08:BA:AD:F0:00:0D

Usage

Valid commands include:

    {`wake`,   `wakes up a machine by mac address or alias`},
    {`list`,   `lists all mac addresses and their aliases`},
    {`alias`,  `stores an alias to a mac address`},
    {`remove`, `removes an alias or a mac address`},

With the following options (mostly apply to the wake command):

    {`v`, `version`,   `prints the application version`},
    {`h`, `help`,      `prints the help menu`},
    {`p`, `port`,      `udp port to send bcast packet to`},
    {`b`, `bcast`,     `broadcast IP to send packet to`},
    {`i`, `interface`, `outbound interface to broadcast using`},

Defaults

The default Broadcast IP is 255.255.255.255 and the UDP Port is 9. Typically the UDP port is either 7 or 9. The default interface is set to "" which tell the program to use any available interface.

Alias file

The alias file is typically stored in the user's Home directory under the path of ~/.config/go-wol/aliases. This is a very simple BoltDB which reads a per-alias Gob made up of a MAC address and an optional preferred outbound interface.

Supported MAC addresses

The following MAC addresses are valid and will match:
01-23-45-56-67-89, 89:0A:CD:EF:00:12, 89:0a:cd:ef:00:12

The following MAC addresses are not (yet) valid:
1-2-3-4-5-6, 01 23 45 56 67 89

CLI examples

Wake up a machine with mac address 00:11:22:aa:bb:cc:

wol wake 00:11:22:aa:bb:cc

Store an alias:

wol alias skynet 00:11:22:aa:bb:cc

Note that when waking up a machine, the wake command pretty much exists for clarity. You can safely omit it (unless your alias name is list, wake, alias or remove).

Wake up a machine using an alias:

wol wake skynet
wol skynet

View all aliases and corresponding MAC addresses:

wol list

Delete an alias:

wol remove skynet

Store an alias to a MAC using a default interface:

wol alias skynet 00:11:22:aa:bb:cc eth0

Specify a Broadcast Interface (Local to the sender):

wol wake skynet -i eth0

# or

wol wake skynet --interface eth0

Note that when specifying an interface to use, you can set that as part of the alias. However, if the -i option is specified, the specified interface will be used and the one in the alias map will be ignored.

Specify the Broadcast Port and IP:

wol wake 00:11:22:aa:bb:cc -b 255.255.255.255 -p 7

# or

wol wake skynet --bcast 255.255.255.255 --port 7

Tests

All commits and PRs will get run on TravisCI and have corresponding coverage reports sent to Coveralls.io.

To run the tests:

go test -v github.com/sabhiram/go-wol/...

Contributors:

  1. @traetox for helping adding the optional outbound interface for MagicPackets, and swapping out the Gob written to disk for a more elegant BoltDB solution.
  2. @mengzhuo for fixing #7.
  3. @gnanderson for updating boltdb.

主要指标

概览
名称与所有者sabhiram/go-wol
主编程语言Go
编程语言Go (语言数: 2)
平台
许可证MIT License
所有者活动
创建于2015-02-08 07:00:53
推送于2023-06-09 14:17:37
最后一次提交2021-12-24 09:40:21
发布数8
最新版本名称v2.0.1 (发布于 )
第一版名称1.0.2 (发布于 )
用户参与
星数457
关注者数8
派生数69
提交数99
已启用问题?
问题数14
打开的问题数3
拉请求数9
打开的拉请求数3
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?