sysinfo.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include <QDebug>
  2. #include <QSysInfo>
  3. #include <QObject>
  4. #include <QProcess>
  5. #include <QNetworkInterface>
  6. #include "sysinfo.h"
  7. SysInfo::SysInfo(QObject *parent) : QObject(parent)
  8. {
  9. kernVersion = QSysInfo::kernelVersion();
  10. currCpuArchitecture = QSysInfo::currentCpuArchitecture();
  11. emit currentCpuArchitectureChanged();
  12. emit kernelVersionChanged();
  13. beepStatus = false;
  14. }
  15. QString SysInfo::getCurrentCpuArchitecture(){
  16. return currCpuArchitecture;
  17. }
  18. QString SysInfo::getKernelVersion(){
  19. return kernVersion;
  20. }
  21. QStringList SysInfo::ifconfig(){
  22. QStringList ret;
  23. QNetworkInterface interface;
  24. QList<QNetworkInterface> interfaceList = interface.allInterfaces();
  25. for( int i =0; i < interfaceList.size(); i++) {
  26. QString iface;
  27. QList<QNetworkAddressEntry> IPList = interfaceList.at(i).addressEntries();
  28. if(IPList.size() > 0) {
  29. iface = interfaceList.at(i).humanReadableName() +"|" + interfaceList.at(i).hardwareAddress() + "|" +
  30. IPList.at(0).ip().toString() + "|" + IPList.at(0).netmask().toString() + "|" + IPList.at(0).broadcast().toString();
  31. ret.append(iface);
  32. }
  33. }
  34. return ret;
  35. }
  36. QString SysInfo::defaultRouter() {
  37. QProcess proc;
  38. QString ret = "";
  39. proc.start("sudo route -n");
  40. proc.waitForFinished(-1);
  41. QString stdout = proc.readAllStandardOutput();
  42. QStringList lines = stdout.split(QRegExp("\n|\r\n|\r"));
  43. if(lines.length() > 1) {
  44. for ( int i = 1; i < lines.length(); i++) {
  45. QStringList cc = lines.at(i).split(QRegExp(" "),QString::SkipEmptyParts);
  46. if(cc.at(0) == "0.0.0.0") {
  47. ret = cc.at(1);
  48. break;
  49. }
  50. }
  51. }
  52. return ret;
  53. }
  54. QStringList SysInfo::dnsServer() {
  55. QProcess proc;
  56. QStringList ret;
  57. proc.start("sudo nslookup .");
  58. proc.waitForFinished(-1);
  59. QString stdout = proc.readAllStandardOutput();
  60. QStringList lines = stdout.split(QRegExp("\n|\r\n|\r"));
  61. if(lines.length() > 0) {
  62. bool doit = false;
  63. for ( int i = 0; i < lines.length(); i++) {
  64. QStringList cc = lines.at(i).split(QRegExp(" |\t"),QString::SkipEmptyParts);
  65. if((cc.length() > 1) && (cc.at(0) == "Name:") && (cc.at(1) == ".")) {
  66. doit = true;
  67. }
  68. if((cc.length() > 0) && (cc.at(0) == "Server:")) {
  69. ret.append(cc.at(cc.length() - 1));
  70. }
  71. if ( (cc.length() > 0) && doit && lines.at(i).contains("Address")) {
  72. ret.append(cc.at(cc.length() - 1));
  73. }
  74. }
  75. }
  76. return ret;
  77. }
  78. void SysInfo::beep() {
  79. if(this->beepStatus) {
  80. QProcess proc;
  81. proc.start("sudo beep");
  82. proc.waitForFinished(-1);
  83. }
  84. return;
  85. }
  86. bool SysInfo::beepOn(bool status) {
  87. beepStatus = status;
  88. return beepStatus;
  89. }