~fredg/rezo

a5813c03de662bad043210357a51941abcb7ab77 — alienus 7 years ago 505e1e9
sort by dB & print nwid with space
1 files changed, 14 insertions(+), 26 deletions(-)

M rezo
M rezo => rezo +14 -26
@@ 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();