-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiwscan
More file actions
executable file
·58 lines (52 loc) · 1.65 KB
/
iwscan
File metadata and controls
executable file
·58 lines (52 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl -w
use strict;
my $iface = 'wlan0';
main();
######################
sub main
{
my $results; my $failed=0;
for(my $tries=0;$tries < 5; $tries++)
{
$results = qx/iwlist $iface scan/;
$failed = $? || ! defined($results);
last unless($failed);
}
if($failed)
{die "Failure in iwlist!\n";}
my %ifaces = parse_iwlist($results);
print join("\t", qw/Sec Signal ESSID/) . "\n";
print '-' x 20 . "\n";
foreach my $iface (keys %ifaces)
{ # Displaying it in this order means I don't need to worry about fixing indents
print join("\t", $ifaces{$iface}{pubpriv}, $ifaces{$iface}{str}, $iface) . "\n";
}
}
sub parse_iwlist
{
my ($in) = @_;
my %ret;
foreach my $celldata (split(/^\s+Cell/ms, $in))
{
next if($celldata =~ /Scan completed/); # Skip the bits before the first cell
my ($cellname) = ($celldata =~ /ESSID:"(.*)"/);
next if($cellname eq ''); # Not much point in listing these
my ($pubpriv) = ($celldata =~ /Encryption key:(.*)/);
my ($str) = ($celldata =~ /Quality=([^ ]*)\//); # XXX You may want to customise this for the
# kinds of data your card(s) return.
# Now that we've parsed it out, we want to fold the possibility of multiple APs with the
# same ESSID into the most sensible/relevant single line of info. This means possibly
# "correcting" previous entries in the %ret table.
if(defined $ret{$cellname})
{ # Possibily fixup existing entry
if($str > $ret{$cellname}{str}) {$ret{$cellname}{str} = $str};
if($pubpriv ne $ret{$cellname}{pubpriv}) {$ret{$cellname}{pubpriv} = 'OMGWTF';} # This *really* would be weird.
}
else # New entry
{
$ret{$cellname}{pubpriv} = $pubpriv;
$ret{$cellname}{str} = $str;
}
}
return %ret;
}