Skip to content

Instantly share code, notes, and snippets.

@BakermanLP
Created March 18, 2016 13:27
Show Gist options
  • Save BakermanLP/4d18cf39e7bea4daef36 to your computer and use it in GitHub Desktop.
Save BakermanLP/4d18cf39e7bea4daef36 to your computer and use it in GitHub Desktop.
iwlist scanning to csv
#!/usr/bin/perl
use POSIX;
$_ = `iwlist wlan0 scanning`;
$n = 0;
for $match (split(/(?=Cell)/)) {
# print "\nCell #######################################\n";
my @lines = split /\n/,$match;
$essid="";
$secure="";
$quality="0";
foreach $_ ( @lines ) {
s/^\s+//;
s/\s+$//;
# print "--".$_."\n";
if ( /ESSID:/ ) {
$essid = $_ ;
$essid =~ s/ESSID\:"(.*)"/$1/;
}
if ( /Encryption key:off/ ) {
$secure="open";
}
if ( /WPA/ ) {
$secure="WPA";
}
if ( /WPA2/ ) {
$secure="WPA2";
}
if ( /WEP/ ) {
$secure="WEP";
}
if ( /Quality=/ ) {
$quality = $_ ;
$quality =~ s#^.*Quality=([0-9]+)/.*$#$1# ;
$quality = floor ( $quality / 70 * 100 );
}
}
if ( $essid !~ /^$/ ) {
print "'".$essid."';";
print "'".$secure."';";
print "'".$quality."'\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment