mirror of
https://github.com/oguzhaninan/Stacer.git
synced 2025-12-23 23:18:31 -05:00
44 lines
948 B
C++
44 lines
948 B
C++
#include "network_info.h"
|
|
|
|
NetworkInfo::NetworkInfo()
|
|
{
|
|
QStringList lines = FileUtil::readListFromFile(PROC_NET_ROUTE);
|
|
|
|
if(lines.count() > 2)
|
|
defaultNetworkInterface = lines
|
|
.at(2)
|
|
.split(QRegExp("\\s+"))
|
|
.first();
|
|
else
|
|
defaultNetworkInterface = "";
|
|
|
|
rxPath = QString("/sys/class/net/%1/statistics/rx_bytes")
|
|
.arg(defaultNetworkInterface);
|
|
|
|
txPath = QString("/sys/class/net/%1/statistics/tx_bytes")
|
|
.arg(defaultNetworkInterface);
|
|
}
|
|
|
|
QString NetworkInfo::getDefaultNetworkInterface() const
|
|
{
|
|
return defaultNetworkInterface;
|
|
}
|
|
|
|
quint64 NetworkInfo::getRXbytes()
|
|
{
|
|
quint64 rx = FileUtil::readStringFromFile(rxPath)
|
|
.trimmed()
|
|
.toLong();
|
|
|
|
return rx;
|
|
}
|
|
|
|
quint64 NetworkInfo::getTXbytes()
|
|
{
|
|
quint64 tx = FileUtil::readStringFromFile(txPath)
|
|
.trimmed()
|
|
.toLong();
|
|
|
|
return tx;
|
|
}
|