-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_ssid.c
37 lines (29 loc) · 906 Bytes
/
list_ssid.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <iwlib.h>
int main(int argc, char *argv[]) {
wireless_scan_head head;
wireless_scan *result;
iwrange range;
int sock;
int i;
char *iface = argv[1];
// Open a socket for wireless operations
sock = iw_sockets_open();
// Get the wireless range information
if (iw_get_range_info(sock, iface, &range) < 0) {
printf("Failed to get range info.\n");
return 1;
}
// Scan for wireless networks
if (iw_scan(sock, iface, range.we_version_compiled, &head) < 0) {
printf("Failed to scan for networks.\n");
return 1;
}
printf("list SSID:\n");
// Iterate over the scan results and print the SSID and signal power
for (result = head.result, i=1; result; result = result->next, i++) {
printf("\t %d: %s\n", i,result->b.essid);
}
// Close the socket
iw_sockets_close(sock);
}