Skip to content

Instantly share code, notes, and snippets.

@sistlind
Last active April 23, 2017 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sistlind/31c27a16fd9ff033da01253a6afe7e94 to your computer and use it in GitHub Desktop.
Save sistlind/31c27a16fd9ff033da01253a6afe7e94 to your computer and use it in GitHub Desktop.
Fritzbox External wakeonlan
<?php
$fritz_url = 'https://public.dyndns.domain:8443';
$fritz_user = 'wakeup';
$fritz_pwd = 'meinpasswort';
$wol_mac='00:aa:bb:cc:dd:ee';
$ch = curl_init(sprintf('%s/login_sid.lua', $fritz_url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
// Get Challenge-String
$l = simplexml_load_string(curl_exec($ch));
$challenge = $l->Challenge;
//echo "challenge: ".$challenge."</br>\n";
// Get SID
$c_str = sprintf("%s-%s", $challenge, $fritz_pwd);
$md_str = md5(iconv("UTF-8", "UTF-16LE", $c_str));
$response=$challenge.'-'.$md_str;
$url=sprintf('%s/login_sid.lua?username=%s&response=%s', $fritz_url,$fritz_user,$response);
//echo $url;
curl_setopt ($ch, CURLOPT_URL, $url );
$response=curl_exec($ch);
//var_dump($response);
$l = simplexml_load_string($response);
//print_r($l);
$sid = $l->SID;
if ($sid=='0000000000000000')
{
echo "Fehler bei der Authorisierung, sid=0!";
die();
}
$url=sprintf('%s/data.lua?sid=%s&page=netDev', $fritz_url, $sid);
curl_setopt ($ch, CURLOPT_URL, $url );
$response=curl_exec($ch);
$l = json_decode($response, true);
//print_r($l['data']);
foreach ($l['data']['active'] as $key => $value){
if (strcasecmp($value['mac'],$wol_mac)==0){
$dev=$l['data']['active'][$key];
echo "MAC found, already active</br>\n";
break;
}
}
foreach ($l['data']['passive'] as $key => $value){
if (strcasecmp($value['mac'],$wol_mac)==0){
$dev=$l['data']['passive'][$key];
echo "MAC found, not active</br>\n";
break;
}
}
//print_r($dev);
$url=sprintf('%s/data.lua?sid=%s&oldpage=net/edit_device.lua&btn_wake=&dev=%s', $fritz_url, $sid,$dev['UID']);
curl_setopt ($ch, CURLOPT_URL, $url );
$response=curl_exec($ch);
if (strcasecmp($response,'{"pid":"netDev"}')==0){
echo "Wakeup of ".$dev['name']." succesful!";
}else{
echo "Error waking ".$dev['name']."!";
}
curl_close($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment