Commit Diff
Diff:
505e1e94c62b2fb5604a061e85ac4dcc994dee06
a5813c03de662bad043210357a51941abcb7ab77
Commit:
a5813c03de662bad043210357a51941abcb7ab77
Tree:
f635ca38d33b97c528a26e56505bf7326df9307c
Author:
alienus <alienusATcahouetDOTnet>
Committer:
alienus <alienusATcahouetDOTnet>
Date:
Fri Apr 10 16:13:06 2015 UTC
Message:
sort by dB & print nwid with space
blob - 784de3e998b338f713148a2662a63908bade0487
blob + c803ad214711c998d98ab093bb29ea0cef8239a9
--- rezo
+++ rezo
@@ -11,7 +11,6 @@ use strict;
use warnings;
use 5.010;
use Getopt::Long;
-use re;
#use Data::Dumper;
# check root
@@ -23,6 +22,7 @@ my $VERSION = '0.0';
# wireless interface & ifconfig path
my $nwif = 'iwn0';
my $ifconfig = '/sbin/ifconfig';
+
# help
sub usage {
say "Usage: $0 [options]\n";
@@ -49,21 +49,14 @@ if ($version) {
# die "Wrong usage, run rezo --help for informations.\n";
# }
-# check
-sub check_ifc {
- if ( ! -e $ifconfig ) {
- die "$ifconfig is not installed, aborting...\n";
- }
-}
-check_ifc();
-
-# status
-
-
# scan
my @netlist;
-#my ($nwid,$SSID,$chan,$channb,$bssid,$bssidn,$db,$agn,$desc);
sub scan {
+ # check ifconfig
+ if ( ! -e $ifconfig ) {
+ die "$ifconfig is not installed, aborting...\n";
+ }
+ # scanning...
open SCANR, "$ifconfig $nwif scan |" or die "Error: $!\n";
while (<SCANR>) {
s/^\s*//;
@@ -71,36 +64,31 @@ sub scan {
if ( ! /^nwid/ ) {
next;
}
- #if ( /^nwid/) {
- # my $line = $_;
-# if ( /\"\w+[\s\w+]*\"/ ) {
if ( /(^nwid\s")(.*)(".*)/ ) {
- # $line =~ /(.*)(\"\w+[\s\w+]*\")(.*)/;
-# $_ =~ /(.*)(\"\w+[_\w+]*\")(.*)/;
my $un = $1;
my $rep = $2;
my $trois = $3;
- $rep =~ s/\s/_/g;
+ $rep =~ s/\s/~~~/g;
$_ = $un . $rep . $trois;
+ s/""/no_name/g;
+ s/"//g;
}
- #say "$line";
push @netlist, [ split ];
- # nwid NEUF_B7B4 chan 1 bssid 00:17:33:c8:b7:b8 220dB 54M privacy,short_slottime,wpa2
- #my ($nwid,$SSID,$chan,$channb,$bssid,$bssidn,$db,$agn,$desc) = ($1,$2,$3,$4,$5,$6,$7,$8,$9);
-
}
close SCANR;
+ # sort by dB
+ @netlist = sort { $b->[6] cmp $a->[6] } @netlist;
return @netlist;
}
scan();
my $inet = @netlist;
-# http://fr.perlmaven.com/les-tableaux-en-perl
sub test {
for my $i (0 .. ($inet - 1) ) {
- #say "$n";
- say "$netlist[$i][1]\t\t: $netlist[$i][6]";
+ my $nb = $i +1;
+ $netlist[$i][1] =~ s/~~~/ /g;
+ say "$nb:\t$netlist[$i][6]:\t$netlist[$i][1]";
}
}
test();
Frédéric Galusik