[wlanfhain] Re: scan.pl

Bruno Randolf br1
So Aug 8 15:22:04 CEST 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sunday 08 August 2004 04:20, Arne Hoffmann wrote:
> # bruno wrote:
> > hier ein kleines script zum wlan scannen (welche frequenzen belegt sind),
> > vielleicht interessierts ja jemanden.
>
> klar, würde mich interessieren, aber ...
>
> > -- Binary/unsupported file stripped by Ecartis --
> > -- Type: application/x-perl
> > -- File: scan.pl
>
> ... ist leider nicht angekommen.

ah shit, dann hier noch mal, hoffentlich klappt das mit dem zeilenumbruch...

bruno

- ---

#!/usr/bin/perl

# scan for occupied WLAN channels
# GPL, br1 at subnet.at
# ./scan.pl: scans once
# ./scan.pl -loop -sleep 0 -iface wlan0

use strict;

use Getopt::Long;

my $IFACE="wlan0";
my $DO_LOOP=0;
my $SLEEP=5;

GetOptions ("iface=s" => \$IFACE,
            "loop!" => \$DO_LOOP,
            "sleep=i" => \$SLEEP,
	     );
	    
# frequency to channel mapping
my $freq2channel = {
	2.412  =>  1,
	2.417  =>  2,
	2.422  =>  3,
	2.427  =>  4,
	2.432  =>  5,
	2.437  =>  6,
	2.442  =>  7,
	2.447  =>  8,
	2.452  =>  9,
	2.457  => 10,
	2.462  => 11,
	2.467  => 12,
	2.472  => 13,
	2.485  => 14,
};

my @list;

sub scan() {
	my $i=-1;
	@list = undef;
	open(SCAN,"iwlist $IFACE scanning|") || warn "can't open pipe from iwlist\n";
	while (<SCAN>) {
		if ( /Address:\s+([\da-z:]+)/io ) {
			$i++;
			$list[$i]->{mac} = $1;
		}
		if ( /ESSID:"(\S+)"/ ) {
			$list[$i]->{essid} = $1;
		}
		if ( /Mode:(\S+)/ ) {
			$list[$i]->{mode} = $1;
		}
		if ( /Frequency:([\d.]+)/ ) {
			$list[$i]->{ch} = $freq2channel->{$1};
		}
		if ( /.*Signal level:([\d+-]+).*level:([\d+-]+)/ ) {
			$list[$i]->{signal} = $1;
			$list[$i]->{noise} = $2;
			$list[$i]->{snr} = $1 - $2;
		}
	}
}

sub print_list() { 
	@list = sort {$b->{snr} <=> $a->{snr}} @list;
	
	print "CH SNR (S/N)    MAC               ESSID\n";
	print "---------------------------------------\n";
	for (@list) {
		printf "%2s %2s (%d/%s)\t%s %s\n", $_->{ch}, $_->{snr}, 
			$_->{signal}, $_->{noise}, $_->{mac}, $_->{essid};
	}
}

if ($DO_LOOP) {
	while (true) {
		scan();
		print_list();
		print "\n";
		sleep($SLEEP);
	}
}
else {
	scan();
	print_list();
}
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFBFikEfg2jtUL97G4RAny3AJ0R1zxWU+fZlQnfqvjATodhdBca/QCeIDZr
x3CgOCspTZ30ht1g6/Fi8bw=
=jBAh
-----END PGP SIGNATURE-----







Mehr Informationen über die Mailingliste Berlin