npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

magic-packet

v1.1.0

Published

发送Wake-on-LAN魔术包唤醒局域网电脑

Readme

magic-packet

一个简单而强大的 Node.js 工具,用于发送 Wake-on-LAN 魔术包唤醒局域网中的计算机。

特性

  • ✅ 发送魔术包唤醒局域网中的计算机
  • ✅ 支持命令行和编程方式使用
  • ✅ 支持自定义广播地址和端口
  • ✅ 支持多次重试机制
  • ✅ 提供Web界面和命令行交互式界面
  • ✅ 支持保存和管理常用设备
  • ✅ 强大的MAC地址验证

安装

全局安装

npm install -g magic-packet

本地安装

npm install magic-packet

使用方法

命令行使用

全局安装后,可以直接使用 magic-packet 命令:

# 基本用法
magic-packet -m XX:XX:XX:XX:XX:XX

# 指定广播地址和端口
magic-packet -m XX:XX:XX:XX:XX:XX -i 192.168.1.255 -p 9

# 设置重试次数
magic-packet -m XX:XX:XX:XX:XX:XX -r 3

# 静默模式(不输出日志)
magic-packet -m XX:XX:XX:XX:XX:XX -s

# 查看帮助
magic-packet --help

在代码中使用

const { sendMagicPacket, isValidMacAddress } = require('magic-packet');

// 验证MAC地址格式
if (isValidMacAddress('XX:XX:XX:XX:XX:XX')) {
  // 发送魔术包
  sendMagicPacket('XX:XX:XX:XX:XX:XX')
    .then(() => console.log('魔术包已发送'))
    .catch(err => console.error('发送失败:', err));
}

// 指定广播地址和端口
sendMagicPacket('XX:XX:XX:XX:XX:XX', '192.168.1.255', 9)
  .then(() => console.log('魔术包已发送'))
  .catch(err => console.error('发送失败:', err));

// 使用高级选项
sendMagicPacket('XX:XX:XX:XX:XX:XX', '192.168.1.255', 9, {
  retries: 3,     // 失败时最多重试3次
  silent: true    // 不输出日志
})
  .then(() => console.log('魔术包已发送'))
  .catch(err => console.error('发送失败:', err));

演示应用

项目包含两个演示应用:

命令行交互式演示

cd demo
npm install
npm start

提供了友好的命令行交互界面,可以:

  • 发送魔术包
  • 保存常用设备
  • 管理设备列表

Web界面演示

cd demo
npm install
npm run web

启动后访问 http://localhost:3006 即可使用Web界面:

  • 发送魔术包
  • 保存和管理设备
  • 直接从设备列表唤醒计算机

参数说明

命令行参数

  • -m, --mac <address>: 目标计算机的 MAC 地址 (格式: XX:XX:XX:XX:XX:XX 或 XX-XX-XX-XX-XX-XX)
  • -i, --ip <address>: 广播地址 (默认: 255.255.255.255)
  • -p, --port <number>: 目标端口 (默认: 9)
  • -r, --retries <number>: 发送失败时的重试次数 (默认: 0)
  • -s, --silent: 静默模式,不输出日志

API参数

sendMagicPacket(macAddress, ipAddress = '255.255.255.255', port = 9, options = {})
  • macAddress (字符串): MAC地址,格式为 XX:XX:XX:XX:XX:XX 或 XX-XX-XX-XX-XX-XX
  • ipAddress (字符串): 广播地址,默认为 255.255.255.255
  • port (数字): 目标端口,默认为 9
  • options (对象): 高级选项
    • retries (数字): 失败时的重试次数,默认为 0
    • silent (布尔值): 是否静默模式,默认为 false

注意事项

  1. 目标计算机必须支持并启用 Wake-on-LAN 功能
  2. 需要在目标计算机的 BIOS/UEFI 设置中启用 Wake-on-LAN
  3. 如果目标计算机在子网中,可能需要指定正确的广播地址
  4. MAC 地址格式必须是 XX:XX:XX:XX:XX:XX 或 XX-XX-XX-XX-XX-XX,其中 XX 是十六进制数字
  5. 在某些系统上,发送 UDP 广播包可能需要特殊权限,可能需要以管理员/root 权限运行

获取目标计算机的 MAC 地址

  1. 在目标计算机开机状态下,使用 ipconfig /all(Windows)或 ifconfig(Linux/Mac)命令查看
  2. 查看目标计算机的网络适配器设置
  3. 查看路由器或网络管理界面中的设备列表

开发

安装依赖

npm install

运行测试

npm test

代码检查

npm run lint

许可证

MIT