Auf Basis von paresys Script(Down/Upstream) habe ich mal etwas weiter gemacht.
Angezeigt werden der Onlinestatus, die Uptime seit der letzten Verbindung und eventuelle Verbindungsfehler.
Das ganze benötigt keine Extension da über UPnP ausgelesen wird.
Legt euch ein Dummymodul an, 3 Variablen, 2x String, 1x Bool eventuell nicht vorhandene Variablenprofile und tragt die IDs im Script ein. Ein Ereignis zum abholen der Daten nach eurem Ermessen.
<?
if($IPS_SENDER == "WebFront") return;
$address = "Fritz.box";
$contentRecv = 'POST /upnp/control/WANIPConn1 HTTP/1.1
Cache-Control: no-cache
Connection: Close
Pragma: no-cache
Content-Type: text/xml; charset="utf-8"
User-Agent: Microsoft-Windows/6.1 UPnP/1.0
SOAPACTION: "urn:schemas-upnp-org:service:WANIPConnection:1#GetStatusInfo"
Content-Length: '.(287+strlen($address)).'
Host: '.$address.':49000
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><m:GetStatusInfo xmlns:m="urn:schemas-upnp-org:service:WANIPConnection:1"/></SOAP-ENV:Body></SOAP-ENV:Envelope>
';
$data = SendPacket($contentRecv);
$connectionStatus = GetTextBetween($data, "<NewConnectionStatus>", "<\/NewConnectionStatus>");
if($connectionStatus == "Connected")
{
SetValue(13384 /*[Fritzbox\Verbindung\Status]*/, true);
}
else
{
SetValue(13384 /*[Fritzbox\Verbindung\Status]*/, false);
}
$lastConnectionError = GetTextBetween($data, "<NewLastConnectionError>", "<\/NewLastConnectionError>");
SetValue(20128 /*[Fritzbox\Verbindung\Verbindungsfehler]*/, $lastConnectionError);
$upTime = GetTextBetween($data, "<NewUptime>", "<\/NewUptime>");
SetValue(39161 /*[Fritzbox\Verbindung\UpTime]*/, gmstrftime('%H:%M:%S', $upTime));
function SendPacket($content)
{
global $address;
$port = 49000 /*[Objekt #49000 existiert nicht]*/;
$fp = fsockopen ($address, $port, $errno, $errstr, 10);
if (!$fp)
{
echo "$errstr ($errno)<br />
";
}
else
{
fputs ($fp, $content);
$ret = "";
while (!feof($fp))
{
$ret.= fgets($fp,128);
}
fclose($fp);
}
if(!(strpos($ret, "200 OK") === false))
{
return $ret;
}
else
{
die("Invalid Response: ".$ret);
}
}
function GetTextBetween($string, $start, $end)
{
preg_match_all("/$start(.*)$end/i", $string, $match);
return $match[1][0];
}
?>
WanIP auslesen!
<?
$address = "Fritz.box";
$contentRecv = 'POST /upnp/control/WANCommonIFC1 HTTP/1.1
Cache-Control: no-cache
Connection: Close
Pragma: no-cache
Content-Type: text/xml; charset="utf-8"
User-Agent: Microsoft-Windows/6.1 UPnP/1.0
SOAPACTION: "urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress"
Content-Length: '.(291+strlen($address)).'
Host: '.$address.':49000
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><m:GetExternalIPAddress xmlns:m="urn:schemas-upnp-org:service:WANIPConnection:1"/></SOAP-ENV:Body></SOAP-ENV:Envelope>
';
$data = SendPacket($contentRecv);
$wanIP = GetTextBetween($data, "<NewExternalIPAddress>", "<\/NewExternalIPAddress>");
SetValue(21456, $wanIP);
function SendPacket($content)
{
global $address;
$port = 49000 /*[Objekt #49000 existiert nicht]*/;
$fp = fsockopen ($address, $port, $errno, $errstr, 10);
if (!$fp)
{
echo "$errstr ($errno)<br />
";
}
else
{
fputs ($fp, $content);
$ret = "";
while (!feof($fp))
{
$ret.= fgets($fp,128);
}
echo $ret;
fclose($fp);
}
if(!(strpos($ret, "200 OK") === false))
{
return $ret;
}
else
{
die("Invalid Response: ".$ret);
}
}
function GetTextBetween($string, $start, $end)
{
preg_match_all("/$start(.*)$end/i", $string, $match);
return $match[1][0];
}
?>