I am building a Wake On Lan program in C# i have found lots of code for WOL but whatever i have found thus far does not work. i believe this is because i cannot enable IP directed broadcast (The customer's security policy will not enable this in order to prevent DOS attacks).
i am looking for a way to send the magic packet over ethernet directly to the requested mac address - right now it seems to be sending over UDP to 255.255.255.255
(What i am don't understand is why it needs to send to 255.255.255.255 and not to the mac itself)
here is the code i have as of now (can't remember where i found it).
public static bool WakeOnLan(string MacAddress)
{
try
{
MacAddress = MacAddress.Replace("-", "");
MacAddress = MacAddress.Replace(":", "");
if (MacAddress.Length != 12)
{
return false;
}
byte[] mac = new byte[6];
for (int k = 0; k < 6; k++)
{
mac[k] = Byte.Parse(MacAddress.Substring(k * 2, 2), System.Globalization.NumberStyles.HexNumber);
}
// WOL packet is sent over UDP 255.255.255.0:40000.
System.Net.Sockets.UdpClient client = new System.Net.Sockets.UdpClient();
client.Connect(System.Net.IPAddress.Broadcast, 4000);
byte[] packet = new byte[17 * 6];
for (int i = 0; i < 6; i++)
packet[i] = 0xFF;
for (int i = 1; i <= 16; i++)
for (int j = 0; j < 6; j++)
packet[i * 6 + j] = mac[j];
client.Send(packet, packet.Length);
return true;
}
catch
{
return false;
}
}
Any help would be greatly appreciated.
thanx