Zum Inhalt springen

WOL PHP Script: Unterschied zwischen den Versionen

Aus Computech CMS Wiki
Simon Zeberli (Diskussion | Beiträge)
Keine Bearbeitungszusammenfassung
Simon Zeberli (Diskussion | Beiträge)
Keine Bearbeitungszusammenfassung
 
Zeile 1: Zeile 1:
  <?php
<syntaxhighlight lang="php" line start="1" highlight="5" enclose="div">
  # Wake on LAN - (c) HotKey@spr.at, upgraded by Murzik
<?php
  # Modified by Allan Barizo http://www.hackernotcracker.com
# Wake on LAN - (c) HotKey@spr.at, upgraded by Murzik
  flush();
# Modified by Allan Barizo http://www.hackernotcracker.com
  function WakeOnLan($addr, $mac,$socket_number) {
flush();
  $addr_byte = explode(':', $mac);
function WakeOnLan($addr, $mac,$socket_number) {
  $hw_addr = '';
$addr_byte = explode(':', $mac);
  for ($a=0; $a <6; $a++) $hw_addr .= chr(hexdec($addr_byte[$a]));
$hw_addr = '';
  $msg = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255);
for ($a=0; $a <6; $a++) $hw_addr .= chr(hexdec($addr_byte[$a]));
  for ($a = 1; $a <= 16; $a++) $msg .= $hw_addr;
$msg = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255);
  // send it to the broadcast address using UDP
for ($a = 1; $a <= 16; $a++) $msg .= $hw_addr;
  // SQL_BROADCAST option isn't help!!
// send it to the broadcast address using UDP
  $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
// SQL_BROADCAST option isn't help!!
  if ($s == false) {
$s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
  echo "Error creating socket!\n";
if ($s == false) {
  echo "Error code is '".socket_last_error($s)."' - " . socket_strerror(socket_last_error($s));
echo "Error creating socket!\n";
  return FALSE;
echo "Error code is '".socket_last_error($s)."' - " . socket_strerror(socket_last_error($s));
  }
return FALSE;
  else {
}
  // setting a broadcast option to socket:
else {
  //$opt_ret = socket_set_option($s, 1, 6, TRUE);
// setting a broadcast option to socket:
  if($opt_ret <0) {
//$opt_ret = socket_set_option($s, 1, 6, TRUE);
    echo "setsockopt() failed, error: " . strerror($opt_ret) . "\n";
if($opt_ret <0) {
    return FALSE;
echo "setsockopt() failed, error: " . strerror($opt_ret) . "\n";
    }
return FALSE;
  if(socket_sendto($s, $msg, strlen($msg), 0, $addr, $socket_number)) {
}
    echo "Magic Packet sent successfully!";
if(socket_sendto($s, $msg, strlen($msg), 0, $addr, $socket_number)) {
    socket_close($s);
echo "Magic Packet sent successfully!";
    return TRUE;
socket_close($s);
    }
return TRUE;
  else {
}
    echo "Magic packet failed!";
else {
    return FALSE;
echo "Magic packet failed!";
    }
return FALSE;
  }
}
  }
}
  // Port number where the computer is listening. Usually, any number between 1-50000 will do. Normally people choose 7 or 9.
}
  $socket_number = "9";
// Port number where the computer is listening. Usually, any number between 1-50000 will do. Normally people choose 7 or 9.
  // MAC Address of the listening computer's network device
$socket_number = "9";
  //$mac_addy = "18:A9:05:49:62:87";
// MAC Address of the listening computer's network device
  $mac_addy = "00:1B:2F:2E:F1:43";
//$mac_addy = "18:A9:05:49:62:87";
  // IP address of the listening computer. Input the domain name if you are using a hostname (like when under Dynamic DNS/IP)
$mac_addy = "00:1B:2F:2E:F1:43";
  $ip_addy = gethostbyname("192.168.1.255");
// IP address of the listening computer. Input the domain name if you are using a hostname (like when under Dynamic DNS/IP)
  WakeOnLan($ip_addy, $mac_addy,$socket_number)
$ip_addy = gethostbyname("192.168.1.255");
  ?>
WakeOnLan($ip_addy, $mac_addy,$socket_number)
?>
</syntaxhighlight>

Aktuelle Version vom 14. April 2013, 09:50 Uhr

<?php
# Wake on LAN - (c) HotKey@spr.at, upgraded by Murzik
# Modified by Allan Barizo http://www.hackernotcracker.com
flush();
function WakeOnLan($addr, $mac,$socket_number) {
$addr_byte = explode(':', $mac);
$hw_addr = '';
for ($a=0; $a <6; $a++) $hw_addr .= chr(hexdec($addr_byte[$a]));
$msg = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255);
for ($a = 1; $a <= 16; $a++) $msg .= $hw_addr;
// send it to the broadcast address using UDP
// SQL_BROADCAST option isn't help!!
$s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
if ($s == false) {
echo "Error creating socket!\n";
echo "Error code is '".socket_last_error($s)."' - " . socket_strerror(socket_last_error($s));
return FALSE;
}
else {
// setting a broadcast option to socket:
//$opt_ret = socket_set_option($s, 1, 6, TRUE);
if($opt_ret <0) {
echo "setsockopt() failed, error: " . strerror($opt_ret) . "\n";
return FALSE;
}
if(socket_sendto($s, $msg, strlen($msg), 0, $addr, $socket_number)) {
echo "Magic Packet sent successfully!";
socket_close($s);
return TRUE;
}
else {
echo "Magic packet failed!";
return FALSE;
}
}
}
// Port number where the computer is listening. Usually, any number between 1-50000 will do. Normally people choose 7 or 9.
$socket_number = "9";
// MAC Address of the listening computer's network device
//$mac_addy = "18:A9:05:49:62:87";
$mac_addy = "00:1B:2F:2E:F1:43";
// IP address of the listening computer. Input the domain name if you are using a hostname (like when under Dynamic DNS/IP)
$ip_addy = gethostbyname("192.168.1.255");
WakeOnLan($ip_addy, $mac_addy,$socket_number)
?>