Auslesen von Netzwerkinformationen
This commit is contained in:
@@ -393,60 +393,53 @@ function getImageFromSignal($signal)
|
||||
|
||||
function getAllNetworkConnections()
|
||||
{
|
||||
$shell_string = '';
|
||||
$output = array();
|
||||
$networkInterfaces = json_decode(shell_exec('ip -j addr'));
|
||||
|
||||
exec('/sbin/ifconfig | grep -E -o "^[[:alnum:][:punct:]]*" | grep -E -v "(lo)" | sed "s/:$//"', $networkInterfaces);
|
||||
foreach ($networkInterfaces as $interface) {
|
||||
if ($interface->ifname != 'lo') {
|
||||
$wirelessOption = [];
|
||||
|
||||
foreach ($networkInterfaces as $interface)
|
||||
$shell_string .= '/sbin/ifconfig ' . $interface . (($networkInterfaces[count($networkInterfaces) - 1] != $interface) ? ' && echo "-#-" && ' : '');
|
||||
|
||||
$streamInterfaces = explode('-#-', shell_exec($shell_string));
|
||||
|
||||
foreach ($streamInterfaces as $index => $streamInterface) {
|
||||
$wirelessOption = '';
|
||||
|
||||
$interface = $networkInterfaces[$index];
|
||||
|
||||
preg_match('#inet(?:[ ]+(?:addr\:)?)([\w\.]+)#', $streamInterface, $ipAddress);
|
||||
preg_match('#(?:HWaddr|ether) ([\w\:]+)#', $streamInterface, $macAddress);
|
||||
preg_match('#RX(?:.*?)bytes[:| ]([\d]+)#', $streamInterface, $bytesReceived);
|
||||
preg_match('#TX(?:.*?)bytes[:| ]([\d]+)#', $streamInterface, $bytesSent);
|
||||
preg_match('#RX(?:.*?)packets[:| ]([\d]+)#', $streamInterface, $packetsReceived);
|
||||
preg_match('#TX(?:.*?)packets[:| ]([\d]+)#', $streamInterface, $packetsSent);
|
||||
|
||||
$output0 = $interface;
|
||||
|
||||
if (substr($output0, 0, 4) == 'wlan') {
|
||||
$streamWirelessInterface = shell_exec('/sbin/iwconfig ' . $output0);
|
||||
|
||||
if (0 == substr_count($streamWirelessInterface, 'Not-Associated')) {
|
||||
$posConfig_start = @strpos($streamWirelessInterface, 'ESSID:"', 0) + 7;
|
||||
$posConfig_end = @strpos($streamWirelessInterface, '"', $posConfig_start);
|
||||
$wirelessOption['ssid'] = trim(substr($streamWirelessInterface, $posConfig_start, ($posConfig_end - $posConfig_start)));
|
||||
|
||||
$posConfig_start = @strpos($streamWirelessInterface, 'Access Point:', 0) + 13;
|
||||
$posConfig_end = @strpos($streamWirelessInterface, 'Bit Rate', $posConfig_start);
|
||||
$wirelessOption['mac'] = trim(substr($streamWirelessInterface, $posConfig_start, ($posConfig_end - $posConfig_start)));
|
||||
|
||||
$posConfig_start = @strpos($streamWirelessInterface, 'Signal level=', 0) + 13;
|
||||
|
||||
if (($posConfig_end = @strpos($streamWirelessInterface, '/100', $posConfig_start)) === false) {
|
||||
$posConfig_end = @strpos($streamWirelessInterface, ' dBm', $posConfig_start);
|
||||
$signal = trim(substr($streamWirelessInterface, $posConfig_start, ($posConfig_end - $posConfig_start)));
|
||||
|
||||
if ($signal <= -100)
|
||||
$wirelessOption['signal'] = 0;
|
||||
elseif ($signal >= -50)
|
||||
$wirelessOption['signal'] = 100;
|
||||
else
|
||||
$wirelessOption['signal'] = 2 * ($signal + 100);
|
||||
} else
|
||||
$wirelessOption['signal'] = trim(substr($streamWirelessInterface, $posConfig_start, ($posConfig_end - $posConfig_start)));
|
||||
foreach ($interface->addr_info as $addr) {
|
||||
if ($addr->family == "inet")
|
||||
$ipAddress = $addr->local;
|
||||
}
|
||||
}
|
||||
$macAddress = $interface->address;
|
||||
$bytesReceived = 0;
|
||||
$bytesSent = 0;
|
||||
$packetsReceived = 0;
|
||||
$packetsSent = 0;
|
||||
|
||||
$output[] = array('interface' => $interface, 'mac' => strtoupper($macAddress[1]), 'ip' => (isset($ipAddress[1])) ? $ipAddress[1] : NULL, 'sent' => $bytesSent[1], 'receive' => $bytesReceived[1], 'option' => $wirelessOption, 'packets' => array('sent' => $packetsSent[1], 'received' => $packetsReceived[1]));
|
||||
if (substr($interface->ifname, 0, 4) == 'wlan') {
|
||||
$streamWirelessInterface = shell_exec('/sbin/iwconfig ' . $interface->ifname);
|
||||
|
||||
if (0 == substr_count($streamWirelessInterface, 'Not-Associated')) {
|
||||
$posConfig_start = @strpos($streamWirelessInterface, 'ESSID:"', 0) + 7;
|
||||
$posConfig_end = @strpos($streamWirelessInterface, '"', $posConfig_start);
|
||||
$wirelessOption['ssid'] = trim(substr($streamWirelessInterface, $posConfig_start, ($posConfig_end - $posConfig_start)));
|
||||
|
||||
$posConfig_start = @strpos($streamWirelessInterface, 'Access Point:', 0) + 13;
|
||||
$posConfig_end = @strpos($streamWirelessInterface, 'Bit Rate', $posConfig_start);
|
||||
$wirelessOption['mac'] = trim(substr($streamWirelessInterface, $posConfig_start, ($posConfig_end - $posConfig_start)));
|
||||
|
||||
$posConfig_start = @strpos($streamWirelessInterface, 'Signal level=', 0) + 13;
|
||||
|
||||
if (($posConfig_end = @strpos($streamWirelessInterface, '/100', $posConfig_start)) === false) {
|
||||
$posConfig_end = @strpos($streamWirelessInterface, ' dBm', $posConfig_start);
|
||||
$signal = trim(substr($streamWirelessInterface, $posConfig_start, ($posConfig_end - $posConfig_start)));
|
||||
|
||||
if ($signal <= -100)
|
||||
$wirelessOption['signal'] = 0;
|
||||
elseif ($signal >= -50)
|
||||
$wirelessOption['signal'] = 100;
|
||||
else
|
||||
$wirelessOption['signal'] = 2 * ($signal + 100);
|
||||
} else
|
||||
$wirelessOption['signal'] = trim(substr($streamWirelessInterface, $posConfig_start, ($posConfig_end - $posConfig_start)));
|
||||
}
|
||||
}
|
||||
|
||||
$output[] = array('interface' => $interface->ifname, 'mac' => strtoupper($macAddress), 'ip' => (isset($ipAddress)) ? $ipAddress : NULL, 'sent' => $bytesSent, 'receive' => $bytesReceived, 'option' => $wirelessOption, 'packets' => array('sent' => $packetsSent, 'received' => $packetsReceived));
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
||||
Reference in New Issue
Block a user