【问题标题】:How to do Wake On LAN by Qt 5?如何通过 Qt 5 进行 LAN 唤醒?
【发布时间】:2015-05-22 10:35:39
【问题描述】:

我找到this tutorial 用于局域网唤醒,但我无法完全理解。它在 Qt3 中实现。我想要可以用 Qt5 编译的 LAN 唤醒功能。如何使用上述代码使用 Qt5 通过 LAN 唤醒计算机?

【问题讨论】:

    标签: c++ qt qt5 packets wake-on-lan


    【解决方案1】:

    这是一个使用 Qt 5 编译的局域网唤醒的实现。该函数将目标计算机的 MAC 地址作为参数并广播相关的 UDP 数据包:

    void MyClass::wakeOnLan(QString MAC)
    {
        char MACAddr [6];
        char MagicPacket [102]; // Magic package for remote boot
    
        int j = sscanf (MAC.toLatin1().data(), "%2x-%2x-%2x-%2x-%2x-%2x",
                        & MACAddr [0], & MACAddr [1], & MACAddr [2], & MACAddr [3], & MACAddr [4], & MACAddr [5]);
    
        // Set to hexadecimal before the magicpacket array 6 characters ff
        memset (MagicPacket, 0xff, 6);
    
        int packetsize = 6; // the beginning of the initial value is 6, do not wrong. I is because the effect of the initial value of the written as 0, it is too effortless.
        // Build MagicPacket.
        for (int i = 0; i <16; i++)
        {
            memcpy (MagicPacket + packetsize, MACAddr, 6);
            packetsize += 6;
        }
    
        QHostAddress FakeAddress;
        FakeAddress.setAddress ("192.168.0.255");
    
        QUdpSocket udpSocket;
        udpSocket.writeDatagram(MagicPacket, 102, FakeAddress, 9);
    }
    

    【讨论】:

    • 如果我想用我的电脑关闭局域网内的多台电脑,如何用qt5实现?谢谢。
    • 我不明白你的意思。我认为最好在一个新问题中提出并完整描述您想要什么。
    • 我不知道有什么方法可以做到这一点。您可能应该将它们配置为不要求输入密码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-04
    • 2013-07-12
    相关资源
    最近更新 更多