这个功能得计算机主板和网卡支持才可以,具体请百度。
01 |
private function wakeOnLan( $ip , $mac , $port ){ |
03 |
$addr_byte = explode ( ':' , $mac ); |
05 |
for ( $i =0; $i <6; $i ++) |
06 |
$hw_addr .= chr (hexdec( $addr_byte [ $i ])); |
07 |
$msg = chr (255). chr (255). chr (255). chr (255). chr (255). chr (255); |
08 |
for ( $i = 1; $i <= 16; $i ++) |
11 |
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); |
12 |
if ( $socket == false) { |
13 |
echo "create socket failed!\n" ; |
14 |
echo "error:'" .socket_last_error( $socket ). "' - " . socket_strerror(socket_last_error( $socket )); |
17 |
$opt_ret = socket_set_option( $socket ,SOL_SOCKET, SO_BROADCAST, TRUE); |
19 |
echo "setsockopt() failed, error: " . strerror( $opt_ret ) . "\n" ; |
22 |
if (socket_sendto( $socket , $msg , strlen ( $msg ), 0, $ip , $port )) { |
24 |
socket_close( $socket ); |
33 |
public function actionTestWakeOnLan(){ |
34 |
$mac = '00:E0:4C:68:07:43' ; |
36 |
$this ->wakeOnLan( $ip , $mac ,7); |
(责任编辑:最模板) |