0Réveil LogoPHP / JavaScript afin de réveiller un PC à distance

I have an HTPC and a net­work serv­er on my net­work. My serv­er is always on, mais l' HTPC sleeps when it is not in use. If I want to sched­ule record­ings remotely I need a way to wake the HTPCThe solu­tion I came up with is to provide a webpage on my serv­er (pass­word pro­tec­ted) that wakes the HTPC and then redir­ects to the web inter­face of the remote con­trol app of the HTPCBelow is the code for any­one interested…

<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);
<body bgcolor='#000022' style='text-align: center; color: white; padding-top: 30px;'>
The TV interface will automatically load <div id="div_name1" style="display:inline;"></div>
<script type="text/javascript">countdown(12, "div_name", 1)</script>
$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;}

Qu'est-ce que tu penses? Envoyez-nous un commentaire ci-dessous! Si vous souhaitez vous abonner s'il vous plaît utiliser le lien d'abonnement dans le menu en haut à droite. Vous pouvez également partager avec vos amis en utilisant les liens sociaux ci-dessous. À votre santé.

Laisser un commentaire