#!/usr/bin/perl # DYNSPY is a Perl script to perform some quality tests on a # wireless communication. # First version was written by Christophe Cattelain # Further versions were written by # Xof & Philippe Teuwen # LICENSE: This script is under GPL # History: # v0.09: # * change "-f" into "-ns" # * add passive mode: disable ping, no need for an IP # * add noflood mode: disable ping flood # v0.08: # * fix duplicate "-n" option & document --nospy # * can now run as normal user, then ping flood is disabled # * adjustable wait state between each iteration, cf "-w#" (by Marc marcb@box100.com) # v0.07: # * add GPL & authors blabla # * add plaintext options # * add iwspy manips & --nospy to avoid them # * copy in stamped log file instead of stderr # * output: add config infos & remove ":" for easier parsing # v0.06 & older: # * history not yet present... $scale="0....+....10...+....20...+....30...+....40...+....50...+....60...+....70...+....80...+....90...+...."; $scalnoise= "*" x 110; $i=110-110; #Scalestring begins @ 110 & dyn-scale is init @ 110 too $signal=1; #default option $delay=0.15;#default value for iteration delay #Options parser for $k (@ARGV) { if ($k =~ /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/){$IP=$k;} elsif ($k eq "-g" or $k eq "--graph" ){$graph=1;} elsif ($k eq "-q" or $k eq "--quality"){$quality=1;} elsif ($k eq "-s" or $k eq "--signal"){$signal=1;} elsif ($k eq "-n" or $k eq "--numeric"){$num=1;} elsif ($k eq "-2" or $k eq "--logfile"){$log=1;} elsif ($k eq "-ns" or $k eq "--nospy"){$nospy=1;} elsif ($k eq "-nf" or $k eq "--noflood"){$noflood=1;} elsif ($k eq "-p" or $k eq "--passive"){$passive=1;} elsif ($k =~ "-w([0-9,.]+)"){$delay=$1;} elsif ($k eq "--debug" ){$debug=1;} elsif ($k eq "-h" or $k eq "--help" ){ print <) { if ($essid =~ /^([a-z]*[0-9])[ \t]*ESSID/) { $spy=1; if ($debug) {printf("Iwspy: got %s, try iwspy %s %s\n", $1, $1, $IP);} `iwspy $1 $IP`; if ($?) {die "Err: Can't spy $IP\n";} } } if (!$spy) {die "Err: iwgetid failed\n";} if ($debug) {printf("Iwspy done.\n");} } # logfile if ($log) { $date=`date "+%y%m%d.%H%M%S"`; $logname="dynlog-$date"; open logfile, ">$logname" or die "Err: Can't create log file\n"; if (!$graph) { # avoid header infos if for graph printf(logfile "# >>>>>>>> Called with:\n# %s", $0); for $k (@ARGV) {printf(logfile " %s", $k);} printf(logfile "\n#\n# >>>>>>>> Date(yymmdd.hhmmss):\n# $date"); printf(logfile "#\n# >>>>>>>> Config:\n"); open IWCFG, "iwconfig|" or die "Err: Can't execute iwconfig\n"; while ($iwcfg=) { printf(logfile "# %s", $iwcfg); } printf(logfile "# >>>>>>>> Capture:\n\n"); } } # scale if ($num){ $scal2="110..+....100..+....90...+....80...+....70...+....60...+....50...+....40...+....30...+....20...+....10...+...."; } else { $scal2="|" x 110; } # main loop while (1) { if (!$passive) { ($root && !$noflood) ? `ping -c1 -f -n -q $IP` : `ping -c1 -n -q $IP`; if ($?) {die "Ping failed\n";} } open STATS, ") { # eth0: 0000 22. 191. 169. 0 0 0 # Signal & Noise Values - 256 = Level in dBm if ($line =~ / +([0-9]+)\. +([0-9]+)\. +([0-9]+)/) { if ($quality){ printf("%d\t%s*\n", $1, substr($scale, 0, $1)); if ($log) {printf(logfile "%s*\n", substr($scale, 0, $1));} } elsif ($graph){ printf("%d\t%d\n",$2-256,$3-256); if ($log) {printf(logfile "%d\t%d\n",$2-256,$3-256);} } else { # Version with noise without automatic rescaling #printf("%s", substr($scalnoise, 0, 110+($3-256))); #printf("%s\n", substr($scal2, 110+($3-256), ($2-$3))); # Version with noise with automatic rescaling printf("S %d\tN %d\t",$2-256,$3-256); if ($log) {printf(logfile "S %d\tN %d\t",$2-256,$3-256);} if (($2-256) > -50) { $i=110-60; }; #if high, shift dyn-scale if (($2-256) < -60) { $i=110-110;}; #trigger if low enough again $j=(110+($3-256)-$i); printf("%s", substr($scalnoise, $i, $j>0 ? $j : 0)); if ($log) {printf(logfile "%s", substr($scalnoise, $i, $j>0 ? $j : 0));} printf("%s\n", substr($scal2, $j>0 ? $i+$j : $i, $j>0 ? ($2-$3) : (110+($2-256)-$i))); if ($log) {printf(logfile "%s\n", substr($scal2, $j>0 ? $i+$j : $i, $j>0 ? ($2-$3) : (110+($2-256)-$i)));} } } } close STATS; select "","","",$delay; }