From 34c4916d8402f056ecbbce249bd25e00cbb25791 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sun, 22 Apr 2018 13:25:15 +0200 Subject: [PATCH] parse ip link and iw dev scan and show visibility --- wap-scan.pl | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 wap-scan.pl diff --git a/wap-scan.pl b/wap-scan.pl new file mode 100755 index 0000000..be5a6e2 --- /dev/null +++ b/wap-scan.pl @@ -0,0 +1,80 @@ +#!/usr/bin/perl +use warnings; +use strict; +use autodie; +use Data::Dump qw(dump); + +my $stat; + +sub path2hostname { + my $hostname = shift; + $hostname =~ s/^.*\///; + $hostname =~ s/_.*$//; + return $hostname; +} + +my $mac2hostname; +foreach my $link ( glob "/dev/shm/wap/*ip_link*" ) { + my $hostname = path2hostname $link; + open(my $fh, '<', $link); + my $if; + while(<$fh>) { + chomp; + if ( m/^\d+:\s(\S+):/ ) { + $if = $1; + } elsif ( m/link\/ether\s(\S+)/ ) { + push @{ $mac2hostname->{$1}->{$hostname} }, $if; + } + } + +} + +warn "# mac2hostname = ",dump($mac2hostname); + +foreach my $scan ( glob "/dev/shm/wap/*iw_*_scan" ) { + my $hostname = path2hostname $scan; + + open(my $fh, '<', $scan); + my $bss; + while(<$fh>) { + chomp; + if ( m/^BSS\s(\S+)\(on\s(\S+)\)/ ) { + $bss = $1; + $stat->{$hostname}->{$bss} = { + if => $2, + }; + + } elsif ( m/^\s*(freq|signal|SSID):\s*(.+)/ ) { + $stat->{$hostname}->{$bss}->{$1} = $2; + } + } + +} + +warn "# stat = ", dump($stat); + + +foreach my $ap ( keys %$stat ) { + foreach my $bss ( keys %{ $stat->{$ap} } ) { + if ( exists $mac2hostname->{$bss} ) { + my $remote = join(',', keys %{ $mac2hostname->{$bss} } ); + print "$ap $remote "; + } else { + print "$ap EXTERNAL "; + } + my $info = dump( $stat->{$ap}->{$bss} ); + $info =~ s/[\n\r\s]+/ /gs; + print "$bss $info\n"; + } +} + +__END__ + +ls /dev/shm/wap/*iw_*_scan | while read file ; do + + hostname=`echo $file | sed -e 's/^.*\///' -e 's/_.*$//'` + + echo `egrep '(BSS|freq:|signal:|SSID:)' $file` \ + | sed -e 's/\n */ /g' -e "s/ *BSS/\n## $hostname BSS/g" -e 's/ *(on \([^ ][^ ]*\)) */ \1 /g' +done + -- 2.20.1