From 44d5db857e98b41c2994d05f0b8ec5aca0d82f34 Mon Sep 17 00:00:00 2001 From: Steffen Ritter Date: Tue, 15 Nov 2016 17:11:15 +0100 Subject: [client] Nicer output of ip addresses under system information * show interface name, ipv4, ipv6, mac * filter loopback interface * filter interfaces which are connected to a bridge --- src/client/informationdialog/informationdialog.cpp | 46 ++++++++++++++++++---- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/src/client/informationdialog/informationdialog.cpp b/src/client/informationdialog/informationdialog.cpp index 275259b..fb3e87c 100644 --- a/src/client/informationdialog/informationdialog.cpp +++ b/src/client/informationdialog/informationdialog.cpp @@ -1,6 +1,8 @@ #include "informationdialog.h" #include #include +#include +#include InformationDialog::InformationDialog() : QDialog() { @@ -28,17 +30,47 @@ void InformationDialog::initTable() { /* NETWORK*/ /* hostnames */ - _tableLayout->addRow(new QLabel(tr("hostname")), new QLabel(QHostInfo::localHostName())); + _tableLayout->addRow(new QLabel("" + tr("hostname") + ""), new QLabel(QHostInfo::localHostName())); /* ips */ - for (QHostAddress a : QNetworkInterface::allAddresses()) { - if (a == QHostAddress::Null || a == QHostAddress::Broadcast || a == QHostAddress::LocalHost || a == QHostAddress::AnyIPv6) + QStringList interfaceFilter; + QString bridgeDevicePath("/sys/devices/virtual/net/"); + QDirIterator it(bridgeDevicePath, QStringList() << "brif", QDir::Dirs, QDirIterator::Subdirectories); + while (it.hasNext()) { + it.next(); + QDir dir = it.filePath(); + dir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); + interfaceFilter += dir.entryList(); + } + + for (QNetworkInterface interface : QNetworkInterface::allInterfaces()) { + + if (interfaceFilter.contains(interface.name()) || interface.flags().testFlag(QNetworkInterface::IsLoopBack)) { + qDebug() << "interface filtered: " << interface.name(); continue; + } + + _tableLayout->addRow("" + interface.name() + "", new QLabel("")); + + for (QNetworkAddressEntry entry : interface.addressEntries()) { + QLabel* label; + QLabel* value; + QHostAddress hostAddr = entry.ip(); + + if (hostAddr == QHostAddress::Null || hostAddr == QHostAddress::Broadcast || hostAddr == QHostAddress::LocalHost + || hostAddr == QHostAddress::AnyIPv6) + continue; - QString ip = a.toString(); + if (hostAddr.protocol() == QAbstractSocket::IPv6Protocol) { + label = new QLabel("IPv6"); + value = new QLabel(hostAddr.toString().split("%").first()); + } else { + label = new QLabel("IPv4"); + value = new QLabel(hostAddr.toString()); + } - QLabel* label = new QLabel(tr("IP") ); - QLabel* value = new QLabel(ip); - _tableLayout->addRow(label, value); + _tableLayout->addRow(label, value); + } + _tableLayout->addRow("MAC", new QLabel(interface.hardwareAddress())); } /* TODO: Add other information */ -- cgit v1.2.3-55-g7522