Introduction
It's strange but I failed to find on the Internet any WOL sample written in C#. So I spent some time making a program to that purpose. It's very simple but it works OK (in our intranet at least).
For waking computers, I use Magic Packet (MAC address of network adapter repeated 16 times).
The actual functionality is implemented like this:
Code
using System;
using System.Net.Sockets;
public class WOLClass:UdpClient
{
public WOLClass():base()
{ }
public void SetClientToBrodcastMode()
{
if(this.Active)
this.Client.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.Broadcast,0);
}
}
...
private void WakeFunction(string MAC_ADDRESS)
{
WOLClass client=new WOLClass();
client.Connect(new
IPAddress(0xffffffff),
0x2fff);
client.SetClientToBrodcastMode();
int counter=0;
byte[] bytes=new byte[1024];
for(int y=0;y<6;y++)
bytes[counter++]=0xFF;
for(int y=0;y<16;y++)
{
int i=0;
for(int z=0;z<6;z++)
{
bytes[counter++]=
byte.Parse(MAC_ADDRESS.Substring(i,2),
NumberStyles.HexNumber);
i+=2;
}
}
int reterned_value=client.Send(bytes,1024);
}