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
877 B
39 lines
877 B
<?php
|
|
|
|
$addrmac = $_GET['mac'];
|
|
|
|
//Préparation du lien pour atteindre l'ordinateur distant
|
|
class Wol {
|
|
private $nic;
|
|
public function wake($mac) {
|
|
$host = "udp://".$_GET['host'];
|
|
$this->nic = fsockopen("$host", 9);
|
|
if ( !$this->nic ) {
|
|
fclose($this->nic);
|
|
return false;
|
|
} else {
|
|
fwrite($this->nic, $this->pacquet($mac));
|
|
fclose($this->nic);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
//Préparation des paquets à envoyer
|
|
private function pacquet($Mac) {
|
|
$packet = "";
|
|
for($i = 0; $i < 6; $i++){$packet .= chr(0xFF);
|
|
}
|
|
for ($j = 0; $j < 16; $j++) {
|
|
for($i = 0; $i < 12; $i=$i + 2) {
|
|
$packet .= chr(hexdec(substr($Mac, $i, 2)));
|
|
}
|
|
}
|
|
return $packet;
|
|
}
|
|
}
|
|
|
|
$wol = new Wol();
|
|
// Ordinateur réveilles-toi !!
|
|
$wol->wake($addrmac);
|
|
|
|
?>
|