Advertisement
CoolRaoul

wol

Sep 6th, 2014
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. <?php
  2.  
  3. flush();
  4. function wol($addr, $mac,$socket_number)
  5. {
  6.    $addr_byte = explode(':', $mac);
  7.    $hw_addr = '';
  8.  
  9.    for ($a=0; $a < 6; $a++)
  10.       $hw_addr .= chr(hexdec($addr_byte[$a]));
  11.  
  12.    $msg = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255);
  13.  
  14.    for ($a = 1; $a <= 16; $a++)
  15.       $msg .= $hw_addr;
  16.  
  17.    $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
  18.    if ($s == false)
  19.    {
  20.       echo "Error creating socket!\n";
  21.       echo "Error code is '".socket_last_error($s)."' - " . socket_strerror(socket_last_error($s));
  22.    }
  23.    else
  24.    {
  25.       $opt_ret = socket_set_option($s, 1, 6, TRUE);
  26.       if($opt_ret < 0)
  27.          echo "setsockopt() failed, error: " . strerror($opt_ret) . "\n";
  28.       $e = socket_sendto($s, $msg, strlen($msg), 0, $addr, $socket_number);
  29.       socket_close($s);
  30.       echo "Magic Packet sent (".$e.") to ".$addr ."\n";
  31.    }
  32. }
  33.  
  34.  
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement