Advertisement
plirof2

wake up on lan PHP, pythons, windows

Feb 9th, 2023 (edited)
923
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. =====================================
  2. <?php
  3. /*
  4. 230209B - OK WORKING
  5. */
  6. //PHP_WOL::send('lab13-bl64-laptopprobpw', '64:31:50:69:7c:06', 9);
  7.  
  8. //https://stackoverflow.com/questions/6055293/wake-on-lan-script-that-works/20065289
  9.  
  10. $broadcast_ip="192.168.1.255";
  11.  
  12. /*
  13. $pc_array= array((64:31:50:69:7e:9e),(00:19:99:6d:54:66),(00:19:99:6a:a2:56)
  14. ,(00:19:99:78:cf:5d),(00:19:99:6e:e7:a1),(00:24:7e:02:01:62),(00:19:99:72:4c:79)
  15. ,(00:18:8b:03:21:8c),(64:31:50:69:3c:85),(00:19:99:7a:36:70),(00:19:99:78:51:f5),(64:31:50:69:7c:06)
  16.     );
  17. */
  18.  
  19. function wol($broadcast, $mac){
  20. $mac_array = preg_split('#:#', $mac); //print_r($mac_array);
  21. $hwaddr = '';
  22.     foreach($mac_array AS $octet){
  23.     $hwaddr .= chr(hexdec($octet));
  24.     }
  25.     //Magic Packet
  26.     $packet = '';
  27.     for ($i = 1; $i <= 6; $i++){
  28.     $packet .= chr(255);
  29.     }
  30.     for ($i = 1; $i <= 16; $i++){
  31.     $packet .= $hwaddr;
  32.     }
  33.     //set up socket
  34.     $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
  35.     if ($sock){
  36.     $options = socket_set_option($sock, 1, 6, true);
  37.         if ($options >=0){    
  38.         $e = socket_sendto($sock, $packet, strlen($packet), 0, $broadcast, 7);
  39.         socket_close($sock);
  40.         }    
  41.     }
  42. }  //end function wol
  43.  
  44.  
  45.  
  46. $mymac = "64:31:50:69:7c:06";
  47. wol($broadcast_ip, $mymac);
  48. echo 'WOL sent to '.$mymac;
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55. ?>
  56.  
  57. ===================================
  58.  
  59.  
  60. ======================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement