123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- #include <QDebug>
- #include <QSysInfo>
- #include <QObject>
- #include <QProcess>
- #include <QNetworkInterface>
- #include "sysinfo.h"
- SysInfo::SysInfo(QObject *parent) : QObject(parent)
- {
- kernVersion = QSysInfo::kernelVersion();
- currCpuArchitecture = QSysInfo::currentCpuArchitecture();
- emit currentCpuArchitectureChanged();
- emit kernelVersionChanged();
- beepStatus = false;
- }
- QString SysInfo::getCurrentCpuArchitecture(){
- return currCpuArchitecture;
- }
- QString SysInfo::getKernelVersion(){
- return kernVersion;
- }
- QStringList SysInfo::ifconfig(){
- QStringList ret;
- QNetworkInterface interface;
- QList<QNetworkInterface> interfaceList = interface.allInterfaces();
- for( int i =0; i < interfaceList.size(); i++) {
- QString iface;
- QList<QNetworkAddressEntry> IPList = interfaceList.at(i).addressEntries();
- if(IPList.size() > 0) {
- iface = interfaceList.at(i).humanReadableName() +"|" + interfaceList.at(i).hardwareAddress() + "|" +
- IPList.at(0).ip().toString() + "|" + IPList.at(0).netmask().toString() + "|" + IPList.at(0).broadcast().toString();
- ret.append(iface);
- }
- }
- return ret;
- }
- QString SysInfo::defaultRouter() {
- QProcess proc;
- QString ret = "";
- proc.start("sudo route -n");
- proc.waitForFinished(-1);
- QString stdout = proc.readAllStandardOutput();
- QStringList lines = stdout.split(QRegExp("\n|\r\n|\r"));
- if(lines.length() > 1) {
- for ( int i = 1; i < lines.length(); i++) {
- QStringList cc = lines.at(i).split(QRegExp(" "),QString::SkipEmptyParts);
- if(cc.at(0) == "0.0.0.0") {
- ret = cc.at(1);
- break;
- }
- }
- }
- return ret;
- }
- QStringList SysInfo::dnsServer() {
- QProcess proc;
- QStringList ret;
- proc.start("sudo nslookup .");
- proc.waitForFinished(-1);
- QString stdout = proc.readAllStandardOutput();
- QStringList lines = stdout.split(QRegExp("\n|\r\n|\r"));
- if(lines.length() > 0) {
- bool doit = false;
- for ( int i = 0; i < lines.length(); i++) {
- QStringList cc = lines.at(i).split(QRegExp(" |\t"),QString::SkipEmptyParts);
- if((cc.length() > 1) && (cc.at(0) == "Name:") && (cc.at(1) == ".")) {
- doit = true;
- }
- if((cc.length() > 0) && (cc.at(0) == "Server:")) {
- ret.append(cc.at(cc.length() - 1));
- }
- if ( (cc.length() > 0) && doit && lines.at(i).contains("Address")) {
- ret.append(cc.at(cc.length() - 1));
- }
- }
- }
- return ret;
- }
- void SysInfo::beep() {
- if(this->beepStatus) {
- QProcess proc;
- proc.start("sudo beep");
- proc.waitForFinished(-1);
- }
- return;
- }
- bool SysInfo::beepOn(bool status) {
- beepStatus = status;
- return beepStatus;
- }
|