Ich habe seit ca. 3 Wochen ein Script zum testen hier laufen, was genau das macht.
Idee war irgendwo im Thread http://www.ip-symcon.de/forum/threads/7566-%28W%29LAN-Watch-Dog glaube ich. Finde es und den Ideengeber gerade nicht wieder.
Bis auf das ich alle 2-5h Stunden Offline Meldungen von meinem HM-LAN-Gateway erhalte, scheint das gut zu funktionieren.
Je nachdem welche FritzBox und welche FW, kann es sein das der Filter bei Zeile 71 / 72 angepaßt werden muss.
Ist also eher eine ‚Bastellösung‘.
Neue Geräte in der FB werden automatisch angelegt, und auch automatisch umbenannt. Ident ist die MAC-Adresse der Geräte.
<?
require_once("Login.inc.php"); // Login ist nicht bestandteil des Scriptes z.B. von der Anrufliste 'klauen'. Funktion bei mir: $SID = Fritz_Login($fritzbox_Adresse, $fritzbox_Password);
$fritzbox_Adresse = 'fritz.box';
$fritzbox_Password = 'xxxxxx';
$only_test1 = false;
$only_test2 = false;
// Bitte erst testen über:
//$only_test1 = true; // Gesamten Inhalt ausgeben
// oder
//$only_test2 = true; // alles zwischen $startstr (Zeile 70) und $stopstr (Zeile 71) ausgeben
// Die Ausgabe sollte ca so aussehen:
/*
[1] = {
["UID"] = "landevice3242",
["_node"] = "landevice0",
["active"] = "1",
["auto_wakeup"] = "0",
["deleteable"] = "2",
["dhcp"] = "0",
["ethernet"] = "1",
["ethernet_port"] = "1",
["guest"] = "0",
["ip"] = "192.168.xxx.xxx",
["ipv6_ifid"] = "::bebe:bebe:bebe:bebe",
["mac"] = "BC:BC:BC:BC:BC:BC",
["manu_name"] = "1",
["name"] = "ESXI",
["online"] = "0",
["parentname"] = "",
["parentuid"] = "",
["plc"] = "0",
["source"] = "0x1210",
["speed"] = "1000",
["static_dhcp"] = "0",
["url"] = "",
["vendorname"] = "",
["wakeup"] = "0",
["wlan"] = "0",
["wlan_UIDs"] = "",
["wlan_show_in_monitor"] = "0",
["wlan_station_type"] = "default"
},
*/
if ($_IPS['SENDER'] == "Execute")
{
IPS_SetHidden($_IPS['SELF'], true);
IPS_SetName($_IPS['SELF'], "Auslese-Skript");
$parentID = IPS_GetParent($_IPS['SELF']);
$parentObject = IPS_GetObject($parentID);
if ($parentObject['ObjectType'] !== 1)
{
$instanceID = IPS_CreateInstance("{485D0419-BE97-4548-AA9C-C083EB82E61E}");
IPS_SetParent($instanceID, $parentID);
$parentID = $instanceID;
IPS_SetParent($_IPS['SELF'], $parentID);
IPS_SetName($instanceID, "Netzwerkgeräte");
}
IPS_SetScriptTimer($_IPS['SELF'], 60);
}
$SID = Fritz_Login($fritzbox_Adresse, $fritzbox_Password);
if ($SID === false) return;
$devicelist = strip_tags(file_get_contents("http://{$fritzbox_Adresse}/net/network_user_devices.lua?sid=".$SID)); //settings/landevice/list
if ($only_test1)
{
print_r ($devicelist);
return;
}
$startstr='["landevice:settings/landevice/list(name,ip,mac,UID,dhcp,wlan,ethernet,active,static_dhcp,manu_name,wakeup,deleteable,source,online,speed,wlan_UIDs,auto_wakeup,guest,url,wlan_station_type,vendorname,parentname,parentuid,ethernet_port,wlan_show_in_monitor,plc,ipv6_ifid)"] = {';
$stopstr='["landevice:settings/landevice0/ipv6addrs0';
$i1 =strpos($devicelist,$startstr)+strlen($startstr)+5;
$i2 = strpos($devicelist,$stopstr);
$devicelist = substr($devicelist,$i1,$i2-$i1-6);
if ($only_test2)
{
print_r ($devicelist);
return;
}
$devices = preg_split('(\[\d+\] = {)',$devicelist);
unset($devices[0]);
foreach ($devices as $device)
{
$rawdata = explode(',',$device);
unset($rawdata[count($rawdata)-1]);
foreach ($rawdata as $data)
{
$temp = explode(' = ',$data);
$devicedata[trim($temp[0])] = trim($temp[1],'"');
}
$ident = str_replace(':','',$devicedata['["mac"]']);
$id = GetOrCreateVariableByIdent(IPS_GetParent($_IPS['SELF']), $ident, $devicedata['["name"]']." (".$devicedata['["ip"]'].")", 0, 0, "~Switch");
if ($devicedata['["active"]']== "1")
{
if (GetValueBoolean($id)== false) SetValueBoolean($id,true);
} else {
if (GetValueBoolean($id)== true) SetValueBoolean($id,false);
}
}
return;
function GetOrCreateVariableByIdent($parent, $ident, $name, $type, $position, $profile="", $hidden=false)
{
global $_IPS;
$vid = @IPS_GetObjectIDByIdent($ident,$parent);
if($vid === false)
{
$vid = IPS_CreateVariable($type);
IPS_SetParent($vid, $parent);
IPS_SetPosition($vid, $position);
IPS_SetHidden($vid, $hidden);
IPS_SetVariableCustomProfile($vid, $profile);
IPS_SetInfo($vid, "this variable was created by script #".$_IPS['SELF']);
IPS_SetIdent($vid,$ident);
}
if (IPS_GetName($vid) <> $name) IPS_SetName($vid, $name);
return $vid;
}
?>
In der Visu habe ich mir mit Links und TabPanes eine Übersicht gebaut (rechte Seite ist die FritzBox).
Hier mal das Login-Script:
<?
function Fritz_Login($fritzbox_Adresse, $fritzbox_Password)
{
$ch = curl_init('http://'.$fritzbox_Adresse.'/login_sid.lua');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$login = curl_exec($ch);
$session_status_simplexml = simplexml_load_string($login);
if ($session_status_simplexml->SID != '0000000000000000')
{
return $session_status_simplexml->SID;
}
else
{
$challenge = $session_status_simplexml->Challenge;
$response = $challenge . '-' . md5(mb_convert_encoding($challenge . '-' . $fritzbox_Password, "UCS-2LE", "UTF-8"));
curl_setopt($ch, CURLOPT_POSTFIELDS, "response={$response}&page=/login_sid.lua");
$sendlogin = curl_exec($ch);
curl_close($ch);
$session_status_simplexml = simplexml_load_string($sendlogin);
if ($session_status_simplexml->SID != '0000000000000000')
{
return $session_status_simplexml->SID;
}
else
{
echo "Fehler: Login fehlgeschlagen";
return false;
}
}
}
?>
Michael