selfjungle Just another WordPress weblog

20Feb/111

iwlist scan perl wrapper

The output of /sbin/iwlist scan is too much for me in most of the cases: I just want to know which WiFis are present, quality and open/passneeded state.

So here is a small perl script for it, the ESSIDs printed in descending order of quality which changed from 1-70 to 1-100.

#!/usr/bin/perl

use warnings;
use strict;

open(LIST, "/sbin/iwlist scan 2>&1 |") or die "Failed: $!\n";

my %wifis;
my $essid;
while () {
        if (/ESSID\:\"(.*)\"/) { $essid = $1; }
        elsif (/Quality=(\d*)\/70/) { $wifis{$essid}->{"quality"} = $1; }
        elsif (/Encryption key\:(\S*)/) { $wifis{$essid}->{"key"} = $1; }
}

sub by_quality {
        $wifis{$b}->{"quality"} <=> $wifis{$a}->{"quality"};
}

print "\n";
foreach $essid ( sort by_quality keys %wifis) {
        printf '%*s %*s   %-d', 30, 
                $essid, 
                6,  $wifis{$essid}->{"key"}=~/on/? "Pass" : "Open" , 
                int($wifis{$essid}->{"quality"}) / 70.0 * 100;
        print "\n";
}
print "\n";

A sample output I got at my flat:

cs0rbagomba@ramen ~ $ wifi_list 

                    gara_dlink   Pass   71
                     TP-Link01   Open   54
                           zaa   Pass   50
                         DBnet   Pass   50
                          anzo   Pass   47
                          3Com   Pass   22
                TP-LINK_9D27F4   Pass   21
                 TP-LINK_TOMEC   Pass   21
                           TNT   Pass   17
                   TimeCapsule   Pass   15
                       hpsetup   Open   14
                  Pannon Cargo   Pass   12
                       Airlive   Pass   10
                TP-LINK_DA3008   Open   10
                                 Open   8
     Szeretetre melto internet   Pass   8
                        KZSNET   Pass   8
                     CEO_iroda   Pass   8
                         Vani2   Pass   5
                      GIGABYTE   Open   4
                        csikos   Pass   2
                TP-LINK_E6395C   Pass   2
                      Dante_88   Pass   2
                        RG60SE   Open   2
                       default   Open   2
                        WIFI99   Pass   1
                         Zsoka   Pass   1
                           IKO   Pass   1

cs0rbagomba@ramen ~ $

PS: TP-Link01 Open - sharing is caring 🙂 default settings rulz

Tagged as: Leave a comment
Comments (1) Trackbacks (0)
  1. why after compiling the code, it displays me “Use of uninitialized value $essid in hash element at (my directory).pl line 11, line 9.
    Use of uninitialized value $essid in hash element at (my directory).pl line 12, line 10.

    Pass 100” ?


Leave a comment

 

No trackbacks yet.