Wake on lan script that works

后端 未结 4 1908
抹茶落季
抹茶落季 2021-01-31 12:17

is there a wake on lan script using a web language preferably php that works? Also one that has some documentation on how to get it to work like what needs to be enabled on your

4条回答
  •  长情又很酷
    2021-01-31 13:07

    Building upon the previous answers. Had to set udp port to 9 and repeat the MAC a couple more times before it worked for me:

    function wol($mac)
    {
        $hwaddr = pack('H*', preg_replace('/[^0-9a-fA-F]/', '', $mac));
    
        // Create Magic Packet
        $packet = sprintf(
            '%s%s',
            str_repeat(chr(255), 6),
            str_repeat($hwaddr, 20)
        );
    
        $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
    
        if ($sock !== false) {
            $options = socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, true);
    
            if ($options !== false) {
                socket_sendto($sock, $packet, strlen($packet), 0, "255.255.255.255", 9);
                socket_close($sock);
            }
        }
    }
    

提交回复
热议问题