Skip to content

Instantly share code, notes, and snippets.

@seungwon0
Created October 30, 2012 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seungwon0/3979646 to your computer and use it in GitHub Desktop.
Save seungwon0/3979646 to your computer and use it in GitHub Desktop.
Get number of APs for each WLAN channel
use strict;
use warnings;
use Android;
my $android = Android->new;
my $scan_results_ref = $android->wifiGetScanResults;
my $results_ref = $scan_results_ref->{result};
my %num_aps;
for my $result_ref ( @{$results_ref} ) {
$num_aps{ $result_ref->{frequency} }++;
}
my %frequency = qw<
1 2412
2 2417
3 2422
4 2427
5 2432
6 2437
7 2442
8 2447
9 2452
10 2457
11 2462
12 2467
13 2472
14 2484
>;
my $total_num_aps = 0;
for my $channel ( sort { $a <=> $b } keys %frequency ) {
my $frequency = $frequency{$channel};
my $num_aps = $num_aps{$frequency} || 0;
printf "Channel %2d (%4d MHz): %2d\n", $channel, $frequency, $num_aps;
$total_num_aps += $num_aps;
}
print q{-} x 25, "\n";
printf "Total : %2d\n", $total_num_aps;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment