pastebin - collaborative debugging tool
kpaste.net RSS


PHP WoL
Posted by Anonymous on Sun 21st Nov 2010 23:14
raw | new post

  1. <?php
  2. // Wake on LAN
  3. //   Author: TorrentialStorm
  4.  
  5. function hex2bin ($s) { return pack("H*", $s); }
  6.  
  7. $mac = "00-01-6c-6d-88-c3";
  8.  
  9. if (strlen($mac) == 12 + 5)
  10.         $mac = str_replace($mac[2], "", $mac);
  11. elseif (strlen($mac) != 12)
  12.         die("Invalid MAC address.");
  13.  
  14. $mac = hex2bin($mac);
  15.  
  16. $data = "";
  17.  
  18. for ($i = 0; $i < 6; $i++)
  19.         $data .= "\xFF";
  20.  
  21. for ($i = 0; $i < 16; $i++)
  22.         $data .= $mac;
  23.  
  24. $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
  25. socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, 1);
  26. socket_sendto($sock, $data, strlen($data), 0, "10.0.0.0", 7);

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at