<?php function wol($broadcast, $mac) { if (strstr($mac, "-")) { $mac_array = explode('-', $mac); } else { $mac_array = explode(':', $mac); } $hwaddr = ''; foreach($mac_array AS $octet) { $hwaddr .= chr(hexdec($octet)); } // Create Magic Packet $packet = ''; for ($i = 1; $i <= 6; $i++) { $packet .= chr(255); } for ($i = 1; $i <= 16; $i++) { $packet .= $hwaddr; } $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); if ($sock) { $options = socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, true); if ($options >=0) { $e = socket_sendto($sock, $packet, strlen($packet), 0, $broadcast, 7); socket_close($sock); } } } $broadcast_ip = "192.168.1.255"; $mac_addr = "94-D0-80-00-06-5D"; wol($broadcast_ip, $mac_addr); ?>
매주 월~금 08시 31분 컴퓨터 자동켜기
crontab -e
31 08 * * 1-5 /home/사용자/script/wol.php