Created
August 3, 2012 16:48
-
-
Save seungwon0/3249402 to your computer and use it in GitHub Desktop.
shows WLAN channel and frequency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# | |
# wlan-channel.pl - shows WLAN channel and frequency | |
# | |
# Shows WLAN channel and frequency. | |
# | |
# Seungwon Jeong <[email protected]> | |
# | |
# Copyright (C) 2012 by Seungwon Jeong | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, but | |
# WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
# General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see | |
# <http://www.gnu.org/licenses/>. | |
use perl5i::2; | |
use Text::UnicodeBox::Table; | |
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 %channel = reverse %frequency; | |
if ( @ARGV == 0 ) { | |
show_table(); | |
} | |
elsif ( @ARGV == 1 ) { | |
my ( $channel, $frequency ); | |
given ( $ARGV[0] ) { | |
when (%frequency) { | |
$channel = $_; | |
$frequency = $frequency{$channel}; | |
} | |
when (%channel) { | |
$frequency = $_; | |
$channel = $channel{$frequency}; | |
} | |
default { | |
print_usage_and_exit(); | |
} | |
} | |
printf "Channel %2d: %d MHz\n", $channel, $frequency; | |
} | |
else { | |
print_usage_and_exit(); | |
} | |
sub print_usage_and_exit { | |
say 'Usage:'; | |
say "\t$PROGRAM_NAME"; | |
say "\t$PROGRAM_NAME channel"; | |
say "\t$PROGRAM_NAME frequency"; | |
exit 2; | |
} | |
sub show_table { | |
say 'List of WLAN Channels:'; | |
my $table = Text::UnicodeBox::Table->new; | |
$table->add_header( Channel => 'Frequency (MHz)' ); | |
for my $channel ( sort { $a <=> $b } keys %frequency ) { | |
$table->add_row( $channel => $frequency{$channel} ); | |
} | |
print $table->render; | |
say 'http://en.wikipedia.org/wiki/List_of_WLAN_channels'; | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment