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