C# wake on lan program does not wake up every client
Asked Answered
P

1

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 :)

Pop answered 12/6, 2014 at 14:41 Comment(0)
C
10

The problem is not the code, it is the machine. Try debugging the hardware.

See, Wake on Lan is a magic packet. The network card gets it and then wakes up the machine.

That is all you do.

The machine then has to wake up properly, and something goes wrong there. There is nothing in your magic packet that can cause this - I would start with the usual suspects (biod versions coming to my mind).

If the machine can be confirmed to have started (and then stops during the start) then this is not a programming issue.

Clovah answered 12/6, 2014 at 14:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.