RabbitRemoteControl icon indicating copy to clipboard operation
RabbitRemoteControl copied to clipboard

Wake on Lan (WOL)

Open volkansari opened this issue 1 year ago • 4 comments

I have been user of Rabbit Remote Control and find its features very valuable. To further enhance its utility, I would like to suggest the addition of Wake-on-LAN (WoL) support. This feature would enable users to remotely wake up devices that are powered off or in sleep mode, making the tool even more versatile.

volkansari avatar Sep 24 '24 15:09 volkansari

WOL is supported by the operating system.

I guess you want to wake up the computer with this program?

Please describe your thoughts in detail.

KangLin avatar Sep 25 '24 02:09 KangLin

To integrate this into Rabbit Remote Control, you could add a right-click context menu option labeled WAKE UP for each offline device in the UI. The MAC address of the device should be stored along with the connection information. When the WAKE UP option is selected, the program would call a function like sendWakeOnLanPacket() to wake up the device.

volkansari avatar Sep 25 '24 06:09 volkansari

for example

#include <QtNetwork/QUdpSocket>
#include <QHostAddress>
#include <QByteArray>
#include <QNetworkDatagram>
#include <QDebug>

void sendWakeOnLanPacket(const QString &macAddress)
{
    // Parse the MAC address
    QStringList macBytes = macAddress.split(":");
    if (macBytes.size() != 6) {
        qDebug() << "Invalid MAC address";
        return;
    }

    QByteArray macByteArray;
    foreach (const QString &byte, macBytes) {
        bool ok;
        macByteArray.append(byte.toUInt(&ok, 16));
        if (!ok) {
            qDebug() << "Invalid byte in MAC address";
            return;
        }
    }

    // Create the magic packet
    QByteArray magicPacket;
    magicPacket.fill(0xFF, 6);  // Start with 6 bytes of 0xFF
    for (int i = 0; i < 16; ++i) {
        magicPacket.append(macByteArray);  // Repeat MAC address 16 times
    }

    // Send the packet via UDP
    QUdpSocket udpSocket;
    QHostAddress broadcastAddress("255.255.255.255");  // Broadcast address
    udpSocket.writeDatagram(magicPacket, broadcastAddress, 9);  // Use port 9

    if (udpSocket.waitForBytesWritten(3000)) {
        qDebug() << "Magic packet sent successfully!";
    } else {
        qDebug() << "Failed to send magic packet!";
    }
}

volkansari avatar Sep 25 '24 06:09 volkansari

There are two or more implementation methods to see which one is suitable.

  • To integrate connect dialog

WakeOnLan

  • Make a separate WOL plug-in to manage all the devices that need wake on lan

KangLin avatar Sep 25 '24 06:09 KangLin

In the end, I chose the plugin. 2024_11_22_14_55_38_791

KangLin avatar Nov 22 '24 06:11 KangLin

图片

KangLin avatar Nov 22 '24 07:11 KangLin