Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Wake on LAN using PHP' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Wake on LAN using PHP
Authored by: karnat10 on Mar 29, '04 08:22:00AM
The magic packet has to be sent over UDP because you won't be able to open a TCP connection with a sleeping host. I've written a PHP function which does all the magic:
function wakeonlan($ip,$mac) {

$socket = fsockopen("udp://".$ip,9,$errno);

if (!$errno) {
	$magicpacket = str_repeat(chr(0xff),6).str_repeat(pack("H*",$mac),16);
	fputs($socket,$magicpacket);
	fclose($socket);
	}
}
Call the function like this:
wakeonlan("12.34.56.78","a0b1c2d3f456");
where the first parameter is the IP address (or hostname) and the second parameter the MAC address of the computer to wake.

It works tip top with my AluBook G4.

[ Reply to This | # ]