假设被唤醒的 PC 网卡 MAC 地址为:01 02 03 04 05 06,则 WoL 魔法包的结构即为:FF FF FF FF FF FF | 01 02 03 04 05 06 ...(Repeat for 16 times totally)... 01 02 03 04 05 06。
其中头部 FF FF FF FF FF FF 固定不变,后部为 MAC 地址的十六次重复。有时数据包还会紧接着4-6字节的密码信息,本文中设为空。
将此数据包由任意空闲端口发送至目标计算机即可唤醒。
代码如下:
/* Author: ReModer Date: 10/03/2023 Func: To realize WoL By Blinker. */
#include<WiFi.h> #include<WiFiUdp.h>
constchar *ssid = "***"; // here is your Wifi id constchar *pswd = "***"; // here is your Wifi password
// Data about WoL int port = **; // every port from 1 to 25565 can be used byte preamble[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; byte macAddress[] = {0x**, 0x**, 0x**, 0x**, 0x**, 0x**}; // **-**-**-** is your MAC Address IPAddress ip(**, **, **, **); // IPAddress is a class with the only constructed function to describe an IP address
// UDP WiFiUDP UDP;
voidUDPSendPacket(IPAddress ip, int port){ UDP.beginPacket(ip, port); UDP.write(preamble, sizeof(preamble)); for (int i = 0; i < 16; i++) UDP.write(macAddress, sizeof(macAddress)); UDP.endPacket(); }
constchar *auth = "***"; // here is your blinker device secret key constchar *ssid = "***"; // here is your Wifi id constchar *pswd = "***"; // here is your Wifi password
// Data about WoL int port = **; // every port from 1 to 25565 can be used byte preamble[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; byte macAddress[] = {0x**, 0x**, 0x**, 0x**, 0x**, 0x**}; // **-**-**-** is your MAC Address IPAddress ip(**, **, **, **); // IPAddress is a class with the only constructed function to describe an IP address
// UDP WiFiUDP UDP;
// Blinker Device BlinkerButton Button("TurnOnPC"); // The name should be samed as the name on APP
voidUDPSendPacket(IPAddress ip, int port){ UDP.beginPacket(ip, port); UDP.write(preamble, sizeof(preamble)); for (int i = 0; i < 16; i++) UDP.write(macAddress, sizeof(macAddress)); UDP.endPacket();
constchar *auth = "3d1d35761f0a"; // here is your blinker device secret key constchar *ssid = "是你蹭不到的"; // here is your Wifi id constchar *pswd = "sncbdd330"; // here is your Wifi password
// Data about WoL int port = 6022; // every port from 1 to 25565 can be used byte preamble[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; byte macAddress[] = {0xB0, 0x25, 0xAA, 0x42, 0x8F, 0xCE}; // **-**-**-** is your MAC Address IPAddress ip(192, 168, 1, 107); // IPAddress is a class with the only constructed function to describe an IP address
// UDP WiFiUDP UDP;
// Blinker Device BlinkerButton Button("TurnOnPC"); // The name should be samed as the name on APP
voidUDPSendPacket(IPAddress ip, int port){ UDP.beginPacket(ip, port); UDP.write(preamble, sizeof(preamble)); for (int i = 0; i < 16; i++) UDP.write(macAddress, sizeof(macAddress)); UDP.endPacket(); }