#!/usr/bin/awk -f
#
# REFERENTIAL CREDITS:
# A large portion of this code is identical to, or derived from
# Justin Jones's WRT scanner and this project would not have been
# possible without his public contribution.
# His code has been optimized [modified] extensively by FragtioN of
# www.jawug.za.net, specifically for the wireless comunity therein.
#
# TODO:
# - Once(if) signal for a node can no longer be obtined, that node will
# be omitted from the list in the next display update to enable a more
# 'live' list which, in turn, will save some space in the display window,
# as well as help avoid confusion... [suggested by: Setsquare]
#
# CHANGES:
# 19/01/2006
# - Credits 'optimizations'... [inspired by: Setsquare]
# 07/01/2006
# - Optimized the UI (everything nicely lined up now (I hope)).
# - Added SNR display; please report any bugs you may encounter with this addition.
# - General code optimizations and fixes to some bugs in Justin's code, namely:
# - Fixed a problem that would cause Ad-Hoc networks to be displayed incorrectly.
#
BEGIN {
IGNORECASE = 1;
command = "wl scan 2> /dev/null ; wl scanresults 2> /dev/null";
red = "\x1b[31m"; green = "\x1b[32m";
greenback="\x1b[42m"; yellow = "\x1b[33m";
cyan = "\x1b[36m"; blue = "\x1b[34m";
blueback = "\x1b[44m"; white = "\x1b[37m";
whiteback = "\x1b[47m"; reset = "\x1b[0m";
underscore = "\x1b[4m"; clear = "\x1b[2J";
home = "\x1b[0;0H"; erase2end = "\x1b[K";
cName = white; cSignal = green;
cNoise = red; cCaps = green;
cRssi = green;
cSnr = yellow;
cChannel = white;
cType = white;
cStrengthLow = blue blueback;
cStrengthMed = white whiteback;
cStrengthHi = green greenback;
cStrengthAged = red;
print clear;
for( ;; )
{
while (command|getline)
{
if(/^SSID/) { cn = $2 ; name[cn] = cn; rssi[cn] = $6 ; noise[cn] = $9 }
if(/^Mode/) {
if(/Ad Hoc/) {
rssi[cn] = $5 ; noise[cn] = $8 ; channel[cn] = $11
}
else {
rssi[cn] = $4 ; noise[cn] = $7 ; channel[cn] = $10
}
}
if(/^BSSID/) { caps[cn] = $4" "$5" "$6" "$7" "$8" "$9" "$10 }
}
close(command)
printf home;
ln = 0;
print white "WRT awk wl Live Scanner v1.0b by FragtioN -- http://www.jawug.za.net/WRTScanScriptn";
print white "SSID RSSI NOISE SNR CHANNEL TYPE";
for (x in name)
{
{
snr = (-1*(noise[x] - rssi[x]));
sigstrength = ((rssi[x] - noise[x])*1.5) + ((rssi[x] +90)*1.5);
if (sigstrength 4) cStrength = cStrengthMed;
if(sigstrength>7) cStrength = cStrengthHi;
if(age[x]=0) cStrength = cStrengthAged;
fmt = "%s%-15s %s%0"sigstrength"d "reset erase2end "\n %s%-4d %s%-4d %s%-4d %s%2s %s%10s " reset erase2end "\n" erase2end "\n";
printf fmt,cName,name[x],cStrength,0,cRssi,rssi[x],cNoise,noise[x],cSnr,snr,cChannel,channel[x],cType,caps[x];
ln++;
}
}
print erase2end;
}
}