Downstream/Upstream Geschwindigkeit der FritzBox auslesen

Da mein Dorf-DSL ein wenig langsam ist, und ich manchmal einfach das Gefühl habe, dass irgendwas meine Leitung belegt, wollte ich schon immer Wissen wie viel gerade auf der Leitung los ist. Die FritzBox kann das… aber mein IP-Symcon wollte es auch schon immer können… :wink:

Jetzt ist es schön im WebFront drin - Wer malt noch passende Icons?

paresy

Installation: Copy&Paste, IP-Adresse angeben, Ausführen, Fertig!


<?

$address = "192.168.1.1";

//Ab hier nichts mehr ändern
$object = IPS_GetObject($IPS_SELF);
$parentID = $object['ParentID'];

$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:WANCommonInterfaceConfig:1#GetTotalBytesReceived"
Content-Length: '.(302+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:GetTotalBytesReceived xmlns:m="urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"/></SOAP-ENV:Body></SOAP-ENV:Envelope>
';

$contentSent = '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:WANCommonInterfaceConfig:1#GetTotalBytesSent"
Content-Length: '.(298+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:GetTotalBytesSent xmlns:m="urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"/></SOAP-ENV:Body></SOAP-ENV:Envelope>
';

//Installer
if ($IPS_SENDER == "Execute")
{
    IPS_SetHidden($IPS_SELF, true);
    IPS_SetName($IPS_SELF, "Auslese-Skript");
    $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, "FritzBox-Auslastung");
        IPS_SetIcon($instanceID, "Gauge");
    }
    IPS_SetScriptTimer($IPS_SELF, 10);
    
    if(!IPS_VariableProfileExists("InternetSpeed_kbs")) {
       IPS_CreateVariableProfile("InternetSpeed_kbs", 2);
       IPS_SetVariableProfileText("InternetSpeed_kbs", "", " kb/s");
       IPS_SetVariableProfileDigits("InternetSpeed_kbs", 2);
    }
}

$totalRecv = GetTextBetween(SendPacket($contentRecv), "<NewTotalBytesReceived>", "<\/NewTotalBytesReceived>");
$totalSent = GetTextBetween(SendPacket($contentSent), "<NewTotalBytesSent>", "<\/NewTotalBytesSent>");
$vidRecv = CreateVariableByName($parentID, "TotalRecv", 2, 1, "", true);
$vidSent = CreateVariableByName($parentID, "TotalSent", 2, 2, "", true);

$varRecv = IPS_GetVariable($vidRecv);
$varSent = IPS_GetVariable($vidSent);

SetValue($vidRecv, $totalRecv);
SetValue($vidSent, $totalSent);

$time = microtime(true);

$vidDn = CreateVariableByName($parentID, "Downstream", 2, 3, "InternetSpeed_kbs");
$vidUp = CreateVariableByName($parentID, "Upstream", 2, 4, "InternetSpeed_kbs");

SetValue($vidDn, max(0, ($totalRecv - $varRecv['VariableValue']['ValueFloat']) / (($time - $varRecv['VariableUpdated'])) / 1024));
SetValue($vidUp, max(0, ($totalSent - $varSent['VariableValue']['ValueFloat']) / (($time - $varSent['VariableUpdated'])) / 1024));

function SendPacket($content) {
    global $address;
    $port = 49000;

    $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/U", $string, $match );
    return $match[1][0];
}

function CreateVariableByName($id, $name, $type, $position, $profile="", $hidden=false)
{
    global $IPS_SELF;
    $vid = @IPS_GetVariableIDByName($name, $id);
    if($vid === false)
    {
        $vid = IPS_CreateVariable($type);
        IPS_SetParent($vid, $id);
        IPS_SetName($vid, $name);
        IPS_SetPosition($vid, $position);
        IPS_SetHidden($vid, $hidden);
        IPS_SetVariableCustomProfile($vid, $profile);
        IPS_SetInfo($vid, "this variable was created by script #$IPS_SELF");
    }
    return $vid;
}

?>

screen.png

Hallo paresy,

erhalte leider eine Fehlermeldung!

„Invalid Response“

Was mach ich falsch bzw. muß ich noch beachten?

Gruß Tommy

Bei mir läufts. Danke

Ist UPNP in deiner Box aktiviert?

Einstellungen -> System -> Netzwerk -> UPNP -> Statusinformationen über UPnP übertragen (empfohlen)

Ja ist es!

Den Gedanken hatte ich auch gleich.
Leider liegt es daran wohl nicht.:confused:

Meine Box 7270 mit 54.04.86 (neueste Firmware)

Gruß Tommy

Hallo
Bei mir die selbe Fehlermeldung

FRITZ!Box Fon WLAN, Firmware-Version 08.04.34
:confused:

Setzt mal anstatt der IP-Adresse, Fritz.box ein. Dann sollte es gehen.

Hab auch die Fehlermeldung. Mit fritz.box geht es garnicht.
Gruß
Jürgen

Damit geht es bei mir.
Warum ist mir noch nicht richtig klar.
Muss an der Zeile :

 $fp = fsockopen ($address, $port, $errno, $errstr, 10);

liegen.
Warum geht eine Ip-Adresse nicht ?
Script wird als fehlerhaft angezeigt.

Hallo,

danke es läuft. Aber nur mit „fritz.box“ sonst not response.

Lukky

Bei mir gehts auch per IP.

Danke für das Script! :smiley:

Geht bei mir auch nur mit „Fritz.box“ ! Warum ? Kann das einer beantworten?

Danke für das Skript.

Gruß Tommy

Wer will im Anhang.

fixed.rar (3.81 KB)

Hi,
ich bekomme immer „Maximum execution time of 30 seconds exceeded on line 91“.
Wird wohl an meiner zu alten 7050 liegen?

Hab meinen Downstream mal geloggt.
So sieht es aus.
Habe ein paar Werte die im minus sind ( ca -250000 ) warum ?
Graph sieht so aus

Ich denke mal Du musst ein eigenes Profiel erstellen und die Unter und Obergrenze selbst festlegen.

Hallo,

ich habe zwei Fragen:

RWN:
Kannst Du das angepasste Script mit den Icons veröffentlichen?

@alle
Bei mir zeigt das Script unsinnige Werte an. Ich liege im Bereich 0,01 - 0,04 KB bei beiden Werten.

im Einsatz ist eine 7390 mit aktuellster Firmware an VDSL 25

Woran kann das liegen

Gruß
Christian

Ob das Script mit der 7390 geht, weiss ich nicht.

Die Icons werden einfach den entsprechenden Variablen zugeordnet.

Variable, Rechtsklick -> bearbeiten. Icon auswählen. Die Icons musst Du dazu erst oben runterladen und in den Ordner webfront\user\icons\fixed legen.

script hat auf Anhieb funktioniert! Danke.
FRITZ!Box WLAN 3170 Firmware-Version 49.04.57

Also 7390 funktioniert mit „fritz.box“ an Steller der IP

Gruß…der Hüsi