0

试图制作一个可以打开服务器的小脚本。我在网上找到了几个例子,但想保持这个基本/简单也能更好地掌握它们是如何组合在一起的。但这不起作用,我意识到我必须在某处指定子网 255 255 255 0 ...

有任何想法吗?

<?php

//check if server is up and running
$alive = fsockopen("XXX.168.1.1", 80, $errno, $errstr, 2);

    if (!$alive) {
        echo "<h1>Server is Down!</h1>";
        echo "I will try to turn it on now...";

        //Creating magic packet
        $mac_address = str_repeat("XXX5XXXX5XXX", 16);
        $msg = "FFFFFFFFFFFF " . "$mac_address" . "000000000000";
        $host_addr = "XXX.168.1.1";
        $host_port = "X";

        //Connect send and close connection
        $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
        $socket_data = socket_send($socket, $msg, strlen($msg), 0, $host_addr, $host_port);

        socket_close($socket);
        //testing
        //echo 
    } else {
        echo "<h1>Server is Up!</h1>";
        fclose($alive);
    }

?>
4

1 回答 1

1

检查这个:http ://www.php.net/manual/en/function.socket-sendto.php#57746

这:http ://www.php.net/manual/en/function.socket-send.php#58574

甚至可能是这样: http: //www.codeproject.com/Articles/11469/Wake-On-LAN-WOL

你会发现你需要将ip地址参数设置为'255.255.255.255'才能进行广播:)

于 2012-05-28T19:37:57.610 回答