note 36335 modified in ref.sockets by bjori

From: Date: Tue, 12 Dec 2006 13:15:27 +0000
Subject: note 36335 modified in ref.sockets by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-120546@lists.php.net to get a copy of this message
>The function, that send the WakeOnLan (WOL, Magic packet) signal: <?php # Wake on LAN - (c) HotKey (at SPR dot AT), upgraded by Murzik <tomurzik@inbox.ru> flush(); function WakeOnLan($addr, $mac) { $addr_byte = explode(':', $mac); $hw_addr = ''; for ($a=0; $a < 6; $a++) $hw_addr .= chr(hexdec($addr_byte[$a])); $msg = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255); for ($a = 1; $a <= 16; $a++) $msg .= $hw_addr; // send it to the broadcast address using UDP // SQL_BROADCAST option isn't help!! $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); if ($s == false) { echo "Error creating socket!\n"; echo "Error code is '".socket_last_error($s)."' - " . socket_strerror(socket_last_error($s)); } else { // setting a broadcast option to socket: $opt_ret = socket_set_option($s, 1, 6, TRUE); if($opt_ret < 0) { echo "setsockopt() failed, error: " . strerror($opt_ret) . "\n"; } $e = socket_sendto($s, $msg, strlen($msg), 0, $addr, 2050); socket_close($s); echo "Magic Packet sent (".$e.") to ".$addr.", MAC=".$mac; } } #WakeOnLan('yourIPorDomain.dyndns.org', 'your:MAC:address'); #WakeOnLan('192.168.0.2', '00:30:84:2A:90:42'); #WakeOnLan('192.168.1.2', '00:05:1C:10:04:05'); //if you have switch or other routing devices in LAN, sendign to // the local IP isn't helps! you need send to the broadcast address like this: WakeOnLan('192.168.1.255', '00:05:1C:10:04:05'); ?> --was-- >The function, that send the WakeOnLan (WOL, Magic packet) signal: <?php # Wake on LAN - (c) HotKey@spr.at, upgraded by Murzik <tomurzik@inbox.ru> flush(); function WakeOnLan($addr, $mac) { $addr_byte = explode(':', $mac); $hw_addr = ''; for ($a=0; $a < 6; $a++) $hw_addr .= chr(hexdec($addr_byte[$a])); $msg = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255); for ($a = 1; $a <= 16; $a++) $msg .= $hw_addr; // send it to the broadcast address using UDP // SQL_BROADCAST option isn't help!! $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); if ($s == false) { echo "Error creating socket!\n"; echo "Error code is '".socket_last_error($s)."' - " . socket_strerror(socket_last_error($s)); } else { // setting a broadcast option to socket: $opt_ret = socket_set_option($s, 1, 6, TRUE); if($opt_ret < 0) { echo "setsockopt() failed, error: " . strerror($opt_ret) . "\n"; } $e = socket_sendto($s, $msg, strlen($msg), 0, $addr, 2050); socket_close($s); echo "Magic Packet sent (".$e.") to ".$addr.", MAC=".$mac; } } #WakeOnLan('yourIPorDomain.dyndns.org', 'your:MAC:address'); #WakeOnLan('192.168.0.2', '00:30:84:2A:90:42'); #WakeOnLan('192.168.1.2', '00:05:1C:10:04:05'); //if you have switch or other routing devices in LAN, sendign to // the local IP isn't helps! you need send to the broadcast address like this: WakeOnLan('192.168.1.255', '00:05:1C:10:04:05'); ?> >TO "judeman at yahoo dot com": I haven't found setsockopt() function ip PHP, I've found an equialent: socket_set_option(). http://php.net/manual/en/ref.sockets.php

« previous php.notes (#120546) next »