Created
March 18, 2016 13:27
-
-
Save BakermanLP/4d18cf39e7bea4daef36 to your computer and use it in GitHub Desktop.
iwlist scanning to csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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