Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wake on lan script that works

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 server etc

like image 974
Michael Avatar asked May 19 '11 07:05

Michael


People also ask

How do I send a magic packet to Wake-on-LAN?

Enable Wake-on-LAN in WindowsRight-click on your Ethernet adapter—mine is called "Intel(R) l211 Gigabit Network Connection"—and select Properties. In the Advanced tab, scroll down to Wake On Magic Packet and ensure it is enabled using the drop-down box on the right.

How do you send a WOL command?

Open the Command Prompt on the computer from which you will be sending the wake-on-LAN command. Type "ping" followed by the computer that you will be sending the wake-on-LAN command's IP address.


1 Answers

function wol($broadcast, $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, 16)
    );

    $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, $broadcast, 7);
            socket_close($sock);
        }
    }
}

Should work - call it with a broadcast IP address, and a MAC address

like image 169
Mez Avatar answered Oct 11 '22 05:10

Mez