Posted By

ne7son on 02/11/12


Tagged

line on Online wake wol


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

tesuji
thastyle


wake online


 / Published in: C#
 

wake online class

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. using System.Net;
  7. using System.Net.Sockets;
  8.  
  9.  
  10.  
  11. namespace wol
  12. {
  13. public class WakeOnLine
  14. {
  15. public WakeOnLine(string mac)
  16. {
  17. WakeUp(mac);
  18.  
  19. }
  20. private void WakeUp(string mac)
  21. {
  22. UdpClient client = new UdpClient();
  23. client.Connect(IPAddress.Broadcast, 0x2fff);
  24. client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 0);
  25. int counter = 0;
  26. byte[] packet = new byte[1024];
  27. for (int i = 0; i < 6; i++)
  28. {
  29. packet[counter++] = 0xFF;
  30. }
  31. for(int y=0;y<16;y++)
  32. {
  33. int i=0;
  34. for(int z=0;z<6;z++)
  35. {
  36. packet[counter++]=
  37. byte.Parse(mac.Substring(i,2),
  38. System.Globalization.NumberStyles.HexNumber);
  39. i+=2;
  40. }
  41. }
  42. client.Send(packet, packet.Length);
  43.  
  44. }
  45.  
  46. }
  47.  
  48.  
  49.  
  50. }

Report this snippet  

You need to login to post a comment.