Click here to Skip to main content
13,449,632 members (42,665 online)
Click here to Skip to main content
Add your own
alternative version


87 bookmarked
Posted 27 Oct 2003

Wake On Lan sample for C#

, 27 Oct 2003
Rate this:
Please Sign up or sign in to vote.
Wake On Lan utility using C#.


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:


using System;
using System.Net.Sockets;

//we derive our class from a standart one
public class WOLClass:UdpClient    
    public WOLClass():base()
    { }
    //this is needed to send broadcast packet
    public void SetClientToBrodcastMode()    
//now use this class
 //MAC_ADDRESS should  look like '013FA049'
 private void WakeFunction(string MAC_ADDRESS)   
      WOLClass client=new WOLClass();
         IPAddress(0xffffffff),  //  i.e broadcast
         0x2fff); // port=12287 let's use this one 
      //set sending bites
      int counter=0;
      //buffer to be send
      byte[] bytes=new byte[1024];   // more than enough :-)
     //first 6 bytes should be 0xFF
     for(int y=0;y<6;y++)
     //now repeate MAC 16 times
     for(int y=0;y<16;y++)
         int i=0;
         for(int z=0;z<6;z++)

     //now send wake up packet
     int reterned_value=client.Send(bytes,1024);


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Satellite Provider Satellite Provider
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionNote - you need to adjust Network Adapter power settings Pin
navyjax218-Apr-17 9:21
membernavyjax218-Apr-17 9:21 
PraiseWorks just fine Pin
Jefferson Motta6-Apr-17 5:33
memberJefferson Motta6-Apr-17 5:33 
QuestionReturn values from WakeFunction ? Pin
Member 123079227-Feb-16 4:47
memberMember 123079227-Feb-16 4:47 
GeneralWorks. Pin
Member 154943823-Sep-14 22:57
memberMember 154943823-Sep-14 22:57 
QuestionNot working on my system.. Pin
Member 1002944612-May-13 22:58
memberMember 1002944612-May-13 22:58 
AnswerRe: Not working on my system.. Pin
Jefferson Motta7-Aug-17 5:37
memberJefferson Motta7-Aug-17 5:37 
GeneralWorks with WOW Pin
David j rundle15-May-12 4:34
memberDavid j rundle15-May-12 4:34 
GeneralThanks! Pin
Anthraxx NL22-Jan-10 10:33
memberAnthraxx NL22-Jan-10 10:33 
GeneralOther example and some theory Pin
memos-software24-Jun-08 20:31
membermemos-software24-Jun-08 20:31 
GeneralError Pin
Christian Rasmussen11-Jun-08 3:11
memberChristian Rasmussen11-Jun-08 3:11 
GeneralRe: Error Pin
Ian_E15-Jun-08 12:35
memberIan_E15-Jun-08 12:35 
GeneralRe: Error Pin
Randy_Miller12-Jul-08 6:14
memberRandy_Miller12-Jul-08 6:14 
GeneralThanks! Pin
devcow11-Jun-07 7:16
memberdevcow11-Jun-07 7:16 
GeneralWorks great ! Pin
A.J.Bauer11-Mar-07 6:32
memberA.J.Bauer11-Mar-07 6:32 
Generalfor broadcasting Pin
plato2926-Jun-06 22:16
memberplato2926-Jun-06 22:16 
Generalbroadcasting Pin
plato2926-Jun-06 21:42
memberplato2926-Jun-06 21:42 
GeneralIP Broadcasting Pin
Save My Soul - (SMS)27-Dec-05 22:29
memberSave My Soul - (SMS)27-Dec-05 22:29 
GeneralThanks for the sample Pin
Radoslav Bielik6-Jan-04 11:05
memberRadoslav Bielik6-Jan-04 11:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01-2016 | 2.8.180318.3 | Last Updated 28 Oct 2003
Article Copyright 2003 by maxburov
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid