0闹钟标志的PHP / JavaScript的远程唤醒电脑

我有一个 HTPC 我的网络上的网络服务器。我的服务器始终开启, 但 HTPC 睡觉时不使用。如果我想远程调度录音,我需要一种方法来唤醒 HTPC.  我想出了一个解决方案是提供我的服务器上的网页 (密码保护) 在唤醒 HTPC 然后重定向到的远程控制应用程序的web界面 HTPC.  下面是任何有兴趣的代码...

<html>
<head>
<meta http-equiv='refresh' content='11;url=address of htpc here' />
<script type="text/javascript">
// time is the number of seconds left
// name is the text part of the container to insert countdown in
// num is the unique id of the container. Allows for more than 1 per page
function countdown(time, name, num)
{
  // grab the element object of the countdown container
  countdownDiv = document.getElementById(name + num);
  // calculate number of minutes from the seconds
  minutes = Math.floor(time / 60);
  // remainder is number of seconds
  seconds = time % 60;
  // add the current countdown display to the container specified
  countdownDiv.innerHTML = 'after ' + seconds + ' seconds, please wait';
  if(time == 1)countdownDiv.innerHTML = 'after ' + seconds + ' second, please wait';
  // if time is up remove the edit div, otherwise repeat every second
  if(time <= 0) countdownDiv.innerHTML = 'now...';
  else setTimeout('countdown(' + --time + ',"' + name + '","' + num + '");', 1000);
}
</script>
</head>
<body bgcolor='#000022' style='text-align: center; color: white; padding-top: 30px;'>
<h2>
The TV interface will automatically load <div id="div_name1" style="display:inline;"></div>
<script type="text/javascript">countdown(12, "div_name", 1)</script>
</h2>
<?php
flush();
$addr_byte = explode(':', "MAC Address of htpc here");
$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;
$s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
$opt_ret = socket_set_option($s, 1, 6, TRUE);
if(socket_sendto($s, $msg, strlen($msg), 0, "local subnet address here", "7")) {socket_close($s);return TRUE;}else {return FALSE;}
?>
</body>
</html>

有你自己的一些想法? 下面放纵自己通过评论! 如果您想订阅,请使用菜单上的订阅链接右上方. 您还可以通过使用下面的链接社会分享这与你的朋友. 干杯.

发表评论