You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
877B

  1. <?php
  2. $addrmac = $_GET['mac'];
  3. //Préparation du lien pour atteindre l'ordinateur distant
  4. class Wol {
  5. private $nic;
  6. public function wake($mac) {
  7. $host = "udp://".$_GET['host'];
  8. $this->nic = fsockopen("$host", 9);
  9. if ( !$this->nic ) {
  10. fclose($this->nic);
  11. return false;
  12. } else {
  13. fwrite($this->nic, $this->pacquet($mac));
  14. fclose($this->nic);
  15. return true;
  16. }
  17. }
  18. //Préparation des paquets à envoyer
  19. private function pacquet($Mac) {
  20. $packet = "";
  21. for($i = 0; $i < 6; $i++){$packet .= chr(0xFF);
  22. }
  23. for ($j = 0; $j < 16; $j++) {
  24. for($i = 0; $i < 12; $i=$i + 2) {
  25. $packet .= chr(hexdec(substr($Mac, $i, 2)));
  26. }
  27. }
  28. return $packet;
  29. }
  30. }
  31. $wol = new Wol();
  32. // Ordinateur réveilles-toi !!
  33. $wol->wake($addrmac);
  34. ?>