Answer the question
In order to leave comments, you need to log in
How to scan wifi networks on ubuntu (c++)?
Good afternoon!
Decided to learn c/c++ in my spare time. Hello World has already been written, and I want a more interesting task.
For example, now I want to sketch a program that will scan and display available wi-fi networks.
Tell me which way to look?
At the moment, I found the Wireless Tools library and an example of its use,
but I could not compile it:
main.cpp:12: undefined reference to `iw_sockets_open'
#include <iostream>
#include "libs/wireless_tools.29/iwlib.h"
int main() {
std::cout << "Hello, World!" << std::endl;
wireless_scan_head head;
wireless_scan *result;
iwrange range;
int sock;
/* Open socket to kernel */
sock = iw_sockets_open();
/* Get some metadata to use for scanning */
if (iw_get_range_info(sock, "wlan0", &range) < 0) {
printf("Error during iw_get_range_info. Aborting.\n");
exit(2);
}
/* Perform the scan */
if (iw_scan(sock, (char *) "wlan0", range.we_version_compiled, &head) < 0) {
printf("Error during iw_scan. Aborting.\n");
exit(2);
}
/* Traverse the results */
result = head.result;
while (NULL != result) {
printf("%s\n", result->b.essid);
result = result->next;
}
exit(0);
}
Answer the question
In order to leave comments, you need to log in
The example is working, you obviously forgot to specify this library to the linker. Your example works with a slight modification (the system #include <iwlib.h>
one instead of yours, well, the interface name is different).g++ -liw test.cc
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question