3 #=======================================================================
5 # File ID: 4e1b3802-f744-11dd-92f4-000475e441b9
9 # ©opyleft 2006– Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
34 $progname =~ s/^.*\/(.*?)$/$1/;
35 our $VERSION = "0.00";
37 Getopt
::Long
::Configure
("bundling");
40 "debug" => \
$Opt{'debug'},
41 "encrypted|e" => \
$Opt{'encrypted'},
42 "help|h" => \
$Opt{'help'},
43 "verbose|v+" => \
$Opt{'verbose'},
44 "version" => \
$Opt{'version'},
45 "xml|x" => \
$Opt{'xml'},
47 ) || die("$progname: Option error. Use -h for help.\n");
49 $Opt{'debug'} && ($Debug = 1);
50 $Opt{'help'} && usage
(0);
51 if ($Opt{'version'}) {
56 if ($Opt{'verbose'}) {
57 system("iwlist ath0 scan | less");
58 } elsif ($Opt{'encrypted'}) {
59 system("iwlist ath0 scan | egrep '(Address:|ESSID:|Quality=|Encryption)' | perl -pe 's/(Encryption key:off)/\x1B[1m$1\x1B[m/g;'");
60 } elsif ($Opt{'xml'}) {
62 if (open(PipeFP
, "iwlist ath0 scan |")) {
63 print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<wlan>\n");
64 my $curr_time = time();
65 my ($Sec, $Min, $Hour, $Day, $Mon, $Year, $Wday, $Yday) = gmtime($curr_time);
66 $Sec = sprintf("%02u", $Sec);
67 $Min = sprintf("%02u", $Min);
68 $Hour = sprintf("%02u", $Hour);
69 $Day = sprintf("%02u", $Day);
70 $Mon = sprintf("%02u", $Mon + 1);
71 $Year = sprintf("%04u", $Year + 1900);
73 my $Date = "$Year-$Mon-${Day}T$Hour:$Min:${Sec}Z";
74 my $end_cell = " </cell>\n";
78 D
("\$Line = '$Line'");
80 $Line =~ s/^(\S+)\s+Scan completed :/sprintf(" <device>%s<\/device
>\n <date
>$Date<\
/date>", txt_to_xml($1))/e
;
82 $Line =~ s
{^Cell
(\d
+) - Address
: (\S
+)$}
84 my $Tmp = $First ?
"" : $end_cell;
86 " <cell num=\"%s\">\n <macaddr>%s<\/macaddr>",
87 txt_to_xml
($1), txt_to_xml
($2)
97 $Line =~ s/^ESSID:"(.*)"$/sprintf(" <essid>$1<\/essid>")/e;
98 $Line =~ s/^Mode:(.*)$/sprintf(" <mode>$1<\/mode>")/e
;
100 Frequency
:(\S
+)\
(\S
+)\ \
(Channel\
(\d
+)\
)$
103 " <freq unit=\"%s\">%s<\/freq>\n <channel>%s<\/channel>",
104 txt_to_xml
($2), txt_to_xml
($1), txt_to_xml
($3)
109 Signal\ level
=(\S
+)\
(\S
+)\s
+
110 Noise\ level
=(\S
+)\
(\S
+)
114 " <quality>%s</quality>\n <signallevel unit=\"%s\">%s</signallevel>\n <noiselevel unit=\"%s\">%s</noiselevel>",
115 txt_to_xml
($1), txt_to_xml
($3), txt_to_xml
($2), txt_to_xml
($5), txt_to_xml
($4)
118 $Line =~ s/Encryption key:(on|off)$/ <encryption>$1<\/encryption
>/;
119 $Line =~ s/^Bit Rate:(\S+) (\S+)$/sprintf(" <rate unit=\"%s\">%s<\/rate
>", txt_to_xml($2), txt_to_xml($1))/e;
120 $Line =~ s/^Extra:([a-z_]+)=(.*)$/sprintf(" <extra name=\"%s\">%s<\/extra>", txt_to_xml
($1), txt_to_xml
($2))/e
;
121 length($Line) && print("$Line\n");
124 $found_cell && print($end_cell);
126 warn("$progname: Unable to open pipe: $!");
130 system("wlanconfig ath0 list scan");
134 # Print program version {{{
135 print("$progname v$VERSION\n");
140 # Send the help message to stdout {{{
143 if ($Opt{'verbose'}) {
149 List available wireless networks.
151 Usage: $progname [options] [file [files [...]]]
156 List networks on a more terse format with encryption info.
160 Show verbose info about the networks. Can be repeated to increase
165 Print version information.
167 Print debugging messages.
175 # Print a status message to stderr based on verbosity level {{{
176 my ($verbose_level, $Txt) = @_;
178 if ($Opt{'verbose'} >= $verbose_level) {
179 print(STDERR
"$progname: $Txt\n");
185 # Print a debugging message {{{
187 my @call_info = caller;
188 chomp(my $Txt = shift);
189 my $File = $call_info[1];
191 $File =~ s
#^.*/(.*?)$#$1#;
192 print(STDERR
"$File:$call_info[2] $$ $Txt\n");
198 # Convert plain text to XML {{{
200 $Txt =~ s/&/&/gs;
203 $Txt =~ s/"/"/gs;
204 $Txt =~ s/"/'/gs;
211 # Plain Old Documentation (POD) {{{
221 [options] [file [files [...]]]
231 =item B<-h>, B<--help>
233 Print a brief help summary.
235 =item B<-v>, B<--verbose>
237 Increase level of verbosity. Can be repeated.
241 Print version information.
245 Print debugging messages.
255 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
259 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
260 This is free software; see the file F<COPYING> for legalese stuff.
264 This program is free software: you can redistribute it and/or modify it
265 under the terms of the GNU General Public License as published by the
266 Free Software Foundation, either version 2 of the License, or (at your
267 option) any later version.
269 This program is distributed in the hope that it will be useful, but
270 WITHOUT ANY WARRANTY; without even the implied warranty of
271 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
272 See the GNU General Public License for more details.
274 You should have received a copy of the GNU General Public License along
276 If not, see L<http://www.gnu.org/licenses/>.
284 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :