3 #include <QNetworkInterface>
6 #include <QDirIterator>
19 _layout =
new QVBoxLayout(
this);
30 qDebug() <<
"create information dialog";
38 new QLabel(QHostInfo::localHostName(),
this));
40 QStringList interfaceFilter;
41 QString bridgeDevicePath(
"/sys/devices/virtual/net/");
42 QDirIterator it(bridgeDevicePath, QStringList(
"brif"), QDir::Dirs, QDirIterator::Subdirectories);
43 while (it.hasNext()) {
45 QDir dir = it.filePath();
46 dir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
47 interfaceFilter += dir.entryList();
50 for (
const auto& interface : QNetworkInterface::allInterfaces()) {
52 if (interfaceFilter.contains(interface.name()) || interface.flags().testFlag(QNetworkInterface::IsLoopBack)) {
53 qDebug() <<
"interface filtered: " << interface.name();
59 for (
const auto &entry : interface.addressEntries()) {
62 QHostAddress hostAddr = entry.ip();
64 if (hostAddr == QHostAddress::Null || hostAddr == QHostAddress::Broadcast || hostAddr == QHostAddress::LocalHost
65 || hostAddr == QHostAddress::AnyIPv6)
68 if (hostAddr.protocol() == QAbstractSocket::IPv6Protocol) {
69 label =
new QLabel(
"IPv6",
this);
70 value =
new QLabel(hostAddr.toString().split(
"%").first(),
this);
72 label =
new QLabel(
"IPv4",
this);
73 value =
new QLabel(hostAddr.toString(),
this);