diff --git a/if_test.cpp b/if_test.cpp index 384f8e94a8ab189c86fe4771e08adfbe60e91d8a..b98487c0176f64ab8b41c8c0a1683abae45237fa 100644 --- a/if_test.cpp +++ b/if_test.cpp @@ -1,22 +1,36 @@ #include <QCoreApplication> #include <QtNetwork/QNetworkInterface> +#define cout QTextStream(stdout) int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); - QList<QNetworkInterface> ifList = QNetworkInterface::allInterfaces(); // now you have interfaces list - foreach (QNetworkInterface iface, ifList) // this should print all interfaces' names + + QList<QNetworkInterface> ifList = QNetworkInterface::allInterfaces(); + + foreach (QNetworkInterface iface, ifList) { - QTextStream(stdout) << iface.humanReadableName() << '\n'; - QTextStream(stdout) << '\t' << "can broadcast? " << iface.CanBroadcast << '\n'; - QTextStream(stdout) << '\t' << "can multicast? " << iface.CanMulticast << '\n'; - QTextStream(stdout) << '\t' << "HW address: " << iface.hardwareAddress() << '\n'; - QTextStream(stdout) << '\t' << "is loopback? " << iface.IsLoopBack << '\n'; - QTextStream(stdout) << '\t' << "is point-to-point? " << iface.IsPointToPoint << '\n'; - QTextStream(stdout) << '\t' << "is running? " << iface.IsRunning << '\n'; - QTextStream(stdout) << '\t' << "is up? " << iface.IsUp << '\n'; - QTextStream(stdout) << '\t' << "is valid? " << iface.isValid() << '\n'; - QTextStream(stdout) << '\t' << "internal name: " << iface.name() << '\n'; + cout << "[+] " << iface.humanReadableName() << '\n'; + cout << '\t' << "[+] Address entries:" << '\n'; + foreach (QNetworkAddressEntry netAddr, iface.addressEntries()){ + cout << "\t\t- broadcast addr: " << netAddr.broadcast().toString() << '\n'; + cout << "\t\t- ip addr: " << netAddr.ip().toString() << '\n'; + cout << "\t\t- subnetmask: " << netAddr.netmask().toString() << '\n'; + } + cout << "\t- can broadcast? " << iface.CanBroadcast << '\n'; + cout << "\t- can multicast? " << iface.CanMulticast << '\n'; + cout << "\t- HW address: " << iface.hardwareAddress() << '\n'; + cout << "\t- is loopback? " << iface.IsLoopBack << '\n'; + cout << "\t- is point-to-point? " << iface.IsPointToPoint << '\n'; + cout << "\t- is running? " << iface.IsRunning << '\n'; + cout << "\t- is up? " << iface.IsUp << '\n'; + cout << "\t- is valid? " << iface.isValid() << '\n'; + cout << "\t- internal name: " << iface.name() << '\n'; + } + cout << "\n------------------ unnamed addresses -------------------\n\n"; + cout << "[+] Local addresses:"; + foreach (QHostAddress hostAddr, QNetworkInterface::allAddresses()){ + cout << "\t- " << hostAddr.toString() << '\n'; } return a.exec(); }