sandunfx

Untitled

Oct 13th, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. public ActionResult WOL()
  2. {
  3. WakeFunction("94C691160D88");
  4. return View();
  5. }
  6.  
  7. public ActionResult Shutdown()
  8. {
  9. return View();
  10. }
  11.  
  12. static void WakeFunction(string MAC_ADDRESS)
  13. {
  14. WOLClass client = new WOLClass();
  15. client.Connect(new
  16. IPAddress(0xffffffff), //255.255.255.255 i.e broadcast
  17. 0x2fff); // port=12287 let's use this one
  18. client.SetClientToBrodcastMode();
  19. //set sending bites
  20. int counter = 0;
  21. //buffer to be send
  22. byte[] bytes = new byte[1024]; // more than enough :-)
  23. //first 6 bytes should be 0xFF
  24. for (int y = 0; y < 6; y++)
  25. bytes[counter++] = 0xFF;
  26. //now repeate MAC 16 times
  27. for (int y = 0; y < 16; y++)
  28. {
  29. int i = 0;
  30. for (int z = 0; z < 6; z++)
  31. {
  32. bytes[counter++] =
  33. byte.Parse(MAC_ADDRESS.Substring(i, 2),
  34. NumberStyles.HexNumber);
  35. i += 2;
  36. }
  37. }
  38.  
  39. //now send wake up packet
  40. int reterned_value = client.Send(bytes, 1024);
  41. }
  42.  
  43. }
  44.  
  45. //we derive our class from a standart one
  46. public class WOLClass : UdpClient
  47. {
  48. public WOLClass()
  49. : base()
  50. { }
  51. //this is needed to send broadcast packet
  52. public void SetClientToBrodcastMode()
  53. {
  54. if (this.Active)
  55. this.Client.SetSocketOption(SocketOptionLevel.Socket,
  56. SocketOptionName.Broadcast, 0);
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment