5

I'm programming a wake on LAN program for our company. There are ca. 40-50 machines in our company and it should wake up every client. To wake up the clients I use this code:

private static void WakeUp(string macAddress)
{
    WOLClass client = new WOLClass();

    client.Connect(new IPAddress(0xffffffff), 0x2fff);
    client.SetClientToBroadcastMode();

    int counter = 0;

    byte[] bytes = new byte[1024];

    for (int e = 0; e < 6; e++)
    {
        bytes[counter++] = 0xFF;
    }

    for (int e = 0; e < 16; e++)
    {
        int i = 0;

        for (int w = 0; w < 6; w++)
        {
            bytes[counter++] = byte.Parse(macAddress.Substring(i, 2), NumberStyles.HexNumber);
            i += 2;
        }
    }

    int returnedValue = client.Send(bytes, 1024);
}

public class WOLClass : UdpClient
{
    public WOLClass()
        : base()
    {

    }

    public void SetClientToBroadcastMode()
    {
        if (this.Active)
        {
            this.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 0);
        }
    }
}

and on button_Click event I just call the method WakeUp(macAddress)

Most clients wake up normally. But on some clients the computer just stops starting and stays in a black monitor with a little underline in the upper left corner. I already checked the macAddress for every client 3 times (ipconfig) and also in debug mode of VS2012. It's always identical and correct. So it cannot be a mac address issue.

Does someone know that problem?

Suggestions appreciated :)

4

1 回答 1

10

问题不在于代码,而在于机器。尝试调试硬件。

看,Wake on Lan 是一个神奇的数据包。网卡得到它,然后唤醒机器。

这就是你所做的一切。

然后机器必须正确唤醒,那里出现问题。你的魔法包中没有任何东西会导致这种情况——我会从通常的嫌疑人开始(我想到的生物版本)。

如果可以确认机器已启动(然后在启动期间停止),则这不是编程问题。

于 2014-06-12T14:44:05.000 回答