Use the PHP network to start the machine

Source: Internet
Author: User
In the area network, the Magic Packet can be sent to the host's network card, Magic Packet has 6 "FF", and then 16 network card MAC, when the main version of the open support Wake on LAN function, the network card received a match the magic Packe T, you can start the computer. (each main version of the Wake on LAN has the same name, such as PME Event Wake up, Power on by PCI Devices ...)

Another effect is the possibility of setting up the network, in the operating system of the installation Manager, the network card in the power management, you need to tick "allow this device to wake the computer."

The fake network card MAC is: 01-02-03-04-05-06

Inside the Magic Packet:

FFFFFFFFFFFF0102030405060102030405060102030405060102030405060102030405060102030405060102030405060102030405060102030405060 10203040506010203040506010203040506010203040506010203040506010203040506010203040506

Then Port 7, or Port 9, which is sent to the computer by using UDP messaging

So the way to do this is to be able to send the Internet to the computer magic Packet, if it is used to send the magic Packet's equipment (Server), there is also an external connection, also can achieve the effect of external network.

The following PHP sends the Magic Packet example source

Wol:wake-on-lan Tutorial with Bonus PHP Script

Only slightly modified as follows:

Class WakeOnLAN {/** * awakens the computer * @param type $addr, target IP or broadcast address (format 01-02-03-04-05-06 or 01:02:03:04:05:06) * @ PARAM type $mac * @param type $port, 7 or 9 * @return Boolean */Public function Wake ($ADDR, $mac, $port)        {$mac = Str_replace ("-", ":", $mac);        $addr _byte = Explode (': ', $mac);        $HW _addr = ";        for ($a = 0; $a < 6; $a + +) {$hw _addr. = Chr (Hexdec ($addr _byte[$a])); }//Start six "FF" $msg = Chr (255). Chr (255). Chr (255). Chr (255). Chr (255).        Chr (255);        16 mac for ($a = 1; $a <=, $a + +) {$msg. = $HW _addr;        }//Open a UDP socket//AF_INET:IP4//sock_dgram:the UDP protocol is based on the this socket type        SOL_UDP: Using UDP messaging to set $skt = Socket_create (Af_inet, Sock_dgram, SOL_UDP);        $err = Array ();            if ($skt = = = False) {$err [] = "Error creating socket!"; $err [] = "Error code is". Socket_last_error ($skt). "' - " .            Socket_strerror (Socket_last_error ($skt));        throw new Exception (implode ("\ n", $err));            } else {//set use broadcast to broadcast messages//$opt _ret = Socket_set_option ($skt, 1, 6, TRUE);            $opt _ret = socket_set_option ($skt, Sol_socket, So_broadcast, true); if ($opt _ret = = = False) {$err [] = "setsockopt () failed, error:".                Socket_strerror (Socket_last_error ($skt));            throw new Exception (implode ("\ n", $err)); } if (Socket_sendto ($skt, $msg, strlen ($msg), 0, $addr, $port)) {//magic Packet sent successful                Ly $res = Trim (Socket_strerror (Socket_last_error ($skt)));                Socket_close ($skt);            return $res;                } else {$err [] = "Magic packet failed!";            throw new Exception (implode ("\ n", $err)); }}}} $WOL = new WakeOnLAN (), try {$res = $WOL->wake (' 192.168.0.255 ', "01-02-03-04-05-06 ", 7);    $res = $WOL->wake (' 192.168.0.255 ', "01-02-03-04-05-06", 9); Var_dump ($res);} catch (Exception $ex) {var_dump ($ex->getmessage ());}
    • The Magic Packet is assigned to broadcast address (for example: 192.168.0.255), which can be sent to all computers in the network, and the Mac will be able to meet the machine.
    • Some computers may transmit port 7 or port 9 to one of them.
    • The original example Socket_set_option ($skt, 1, 6, TRUE), 1, 6 is replaced with the constant number, because different environment sol_socket, so_broadcast the constant straight seems different. See all Soket Constants http://php.net/manual/en/sockets.constants.php#108291
      $a = get_defined_constants (TRUE); foreach ($a [' sockets '] as $constant = = $value) {    printf ("%-25s%d", $constant, $v Alue);}

Internet Awakening-Wikipedia, the free encyclopedia

Setting up Windows 8 Internet wake-Up (Wake on LAN)-dark threading

Php:socket_create-manual

Php:socket_set_option-manual

Php:socket_get_option-manual

Arduino-php:send an UDP broadcast message, and wait the Response-stack Overflow

The primitive tribe of small Letter pigs: [TCP/IP Illustrated] Broadcasting & multicasting
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.