decently working showing available network interfaces
This commit is contained in:
@@ -1,6 +1,23 @@
|
|||||||
#include "networkscanner.h"
|
#include "networkscanner.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
|
#include <iwlib.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
std::string exec(const char* cmd) {
|
||||||
|
std::array<char, 128> buffer;
|
||||||
|
std::string result;
|
||||||
|
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
|
||||||
|
if (!pipe) {
|
||||||
|
throw std::runtime_error("popen() failed!");
|
||||||
|
}
|
||||||
|
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
|
||||||
|
result += buffer.data();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
QList<Network> NetworkScanner::scanForNetworks()
|
QList<Network> NetworkScanner::scanForNetworks()
|
||||||
{
|
{
|
||||||
@@ -11,5 +28,20 @@ QList<Network> NetworkScanner::scanForNetworks()
|
|||||||
Network example1 = Network("Gita 2.4Ghz");
|
Network example1 = Network("Gita 2.4Ghz");
|
||||||
networks.append(example1);
|
networks.append(example1);
|
||||||
|
|
||||||
|
std::string result = exec("nmcli -t -f ssid dev wifi");
|
||||||
|
|
||||||
|
std::vector<std::string> ssids;
|
||||||
|
std::istringstream iss(result);
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(iss, line)) {
|
||||||
|
ssids.push_back(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const std::string &ssid : ssids) {
|
||||||
|
std::cout << ssid << std::endl;
|
||||||
|
Network newNetwork = Network(ssid.c_str());
|
||||||
|
networks.append(newNetwork);
|
||||||
|
}
|
||||||
|
|
||||||
return networks;
|
return networks;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user