-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus.php
79 lines (66 loc) · 2.5 KB
/
status.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
// IP or Name of the Fritz!Box
$fritzbox = "fritz.box";
// refreshrate
$pollrate = 0.5;
for ($i = 1; $i <= INF; $i++) {
$client = new SoapClient(
null,
array(
'location' => "http://10.201.240.1:49000/igdupnp/control/WANCommonIFC1",
'uri' => "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1",
'soapaction' => "",
'noroot' => True
)
);
$status = $client->GetCommonLinkProperties();
/*
'NewWANAccessType' => string 'DSL' (length=3)
'NewLayer1UpstreamMaxBitRate' => string '39040000' (length=8)
'NewLayer1DownstreamMaxBitRate' => string '103880000' (length=9)
'NewPhysicalLinkStatus' => string 'Up' (length=2)
*/
$status2 = $client->GetAddonInfos();
//print_r($status);
// print_r($status2);
// Bytes in Bits umrechnen (Ermittelte Werte * 8)
$ByteSendRate = $status2['NewByteSendRate'];
$ByteReceiveRate = $status2['NewByteReceiveRate'];
if ( $status['NewPhysicalLinkStatus'] == 'up'){
$linkColor = "1;31m";
} else {
$linkColor = "1;32m";
}
echo " \r";
$statusinfo = "\e[1m" . strtoupper($status['NewWANAccessType']) . "\e[0m (\e[" . $linkColor . $status['NewPhysicalLinkStatus'] . "\e[0m)";
$outputup = "\e[1mUpstream:\033[0m \e[" . HumanReadable($ByteSendRate) . "/s \e[0m" ;
$outputdown = "\e[1mDownstream:\e[0m \e[" . HumanReadable($ByteReceiveRate) . "/s \e[0m";
echo $statusinfo . " " . $outputup ."\t" . $outputdown . "\r";
sleep($pollrate);
}
function HumanReadable ($byte){
switch (strlen ($byte)) {
case (strlen($byte) >= 4 and strlen($byte) <7):
// KByte
$color = "1;32m"; //Light Green
$rate = round($byte / 1024,2);
return $color . $rate . " KByte";
break;
case (strlen($byte) >= 7 and strlen($byte) <10):
//MByte
$color = "1;33m"; //Yellow
$rate = round($byte / 1024 / 1024,2);
return $color . $rate . " MByte";
break;
case (strlen($byte) >= 10 and strlen($byte) <13):
//GByte
$color = "1;31m"; //Light Red
$rate = round($byte / 1024 / 1024 / 1024,2);
return $color . $rate . " GByte";
break;
default:
$color = "1;36m"; //Light Cyan
$rate = round($byte,2);
return $color . $rate . " Byte";
}
}