socket extension.'; //Confirm the IP Address $MyIP=gethostbynamel($ip); if($MyIP===FALSE) return 'Invalid IP address or domain name passed.'; $ip=$MyIP[0]; //Confirm the port if(preg_match('/[^0-9]/', $port) || !strlen($port)) return 'Port number must be a positive integer.'; //Prepare mac address if(!preg_match('/^([0-9A-F]{2}[^0-9A-F]){5}[0-9A-F]{2}$/i', $mac)) //Confirm mac address is valid return 'The mac address must be 6 hex digits long seperated by a single non hexedecimal character, e.x. 00:01:02:30:AB:FF .'; $AddrHex=preg_split('/[^0-9A-G]/i', $mac); //Split up mac address into bytes $mac=implode(':', $AddrHex); //Redo the mac address into a proper format $MacAddr=""; for($i=0;$i<6;$i++) //Turn the hex strings into characters $MacAddr.=chr(hexdec($AddrHex[$i])); //Prepare the magic packet - $FortyEight1s=str_repeat(chr(255), 6); //48 binary 1s in a row $Msg=$FortyEight1s.$MacAddr.chr(0x8).chr(0x42).$FortyEight1s; //This specific magic packet format seems to work best for($i=0;$i<16;$i++) $Msg.=$MacAddr; //Send the magic packet //Create the UDP socket $s=socket_create(AF_INET,SOCK_DGRAM,SOL_UDP); if($s===false) return 'Error creating socket!
Error code is "'.socket_last_error($s).'" - '.socket_strerror(socket_last_error($s)); //Set the socket to broadcast $opt_ret=socket_set_option($s,SOL_SOCKET,SO_BROADCAST,1); if($opt_ret<0) return 'setsockopt() failed, error: '.strerror($opt_ret); //Send the packet $e=socket_sendto($s,$Msg,strlen($Msg),0,$ip,$port); socket_close($s); //Confirm correct packet if($e!=116) //Confirm 116 bytes were sent return "Packet may not have sent correctly. ($e)"; //Return how many bytes were sent //Return success return "$ip of MAC $mac should now boot through UDP port $port if it supports Wake On LAN."; } //The rest is the client GUI ?>
Name Value Format
IP Address/Domain or
MAC Address 00:01:02:30:AB:FF
UDP Port Number 123

Dakusan's Wake On LAN information