2015-12-10 10:17:03 -07:00
|
|
|
#!/usr/bin/perl
|
|
|
|
=for commnet
|
|
|
|
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
|
|
|
Copyright (C) 2015 Joe Ayers ae6xe@arrl.net and Darryl Quinn K5DLQ
|
|
|
|
See Contributors file for additional contributors
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation version 3 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Additional Terms:
|
|
|
|
|
|
|
|
Additional use restrictions exist on the AREDN(TM) trademark and logo.
|
|
|
|
See AREDNLicense.txt for more info.
|
|
|
|
|
|
|
|
Attributions to the AREDN Project must be retained in the source code.
|
|
|
|
If importing this code into a new or existing project attribution
|
|
|
|
to the AREDN project must be added to the source code.
|
|
|
|
|
|
|
|
You must not misrepresent the origin of the material contained within.
|
|
|
|
|
|
|
|
Modified versions must be modified to attribute to the original source
|
|
|
|
and be marked in reasonable ways as differentiate it from the original
|
|
|
|
version.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
$MAXLINES=2880; # 2 days worth
|
|
|
|
$tmpdir="/tmp/snrlog";
|
|
|
|
$sigdir="/sys/kernel/debug/ieee80211/phy0/netdev\:wlan0/stations";
|
|
|
|
|
|
|
|
$nf = `iw wlan0 survey dump | grep -A 1 'in use' | tail -1`;
|
|
|
|
$nf =~ s/^[^-\d]*([-\d]+).*$/$1/;
|
|
|
|
chomp $nf;
|
2015-12-11 11:25:38 -07:00
|
|
|
|
2015-12-10 10:17:03 -07:00
|
|
|
if (! -e $tmpdir ) { system("mkdir $tmpdir > /dev/null"); }
|
|
|
|
|
|
|
|
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
|
2015-12-11 00:04:34 -07:00
|
|
|
$d = sprintf ("%02d/%02d %02d:%02d:%02d",$mon+1, $mday,$hour, $min, $sec);
|
2015-12-10 10:17:03 -07:00
|
|
|
|
2015-12-11 11:25:38 -07:00
|
|
|
foreach $sigmac ( `ls $sigdir` )
|
2015-12-10 10:17:03 -07:00
|
|
|
{
|
|
|
|
chomp $sigmac;
|
2015-12-11 11:25:38 -07:00
|
|
|
$filename = `ls $tmpdir/$sigmac*` ;
|
|
|
|
$filename =~ /^.*\/([^-]*)-(.*)$/;
|
|
|
|
$isFile = $1;
|
|
|
|
$hnamef = $2;
|
|
|
|
|
2015-12-10 10:17:03 -07:00
|
|
|
chomp ($ip = `cat /proc/net/arp | grep $sigmac | cut -f1 -d\" "`);
|
|
|
|
$hname="";
|
2015-12-11 11:25:38 -07:00
|
|
|
foreach(`nslookup $ip`)
|
|
|
|
{
|
|
|
|
next unless ($hname) = /Address 1: $ip (\S+)/;
|
2015-12-10 10:17:03 -07:00
|
|
|
$hname =~ s/\..*$// ;
|
|
|
|
break;
|
2015-12-11 11:25:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (($hnamef and $hnamef eq $hname ) or ($hname and ! $isFile ))
|
|
|
|
{
|
|
|
|
$sigdat = "$sigmac-$hname";
|
|
|
|
}
|
|
|
|
elsif ( $hnamef eq $ip and $hname )
|
|
|
|
{
|
|
|
|
system("mv $tmpdir/$sigmac-$ip $tmpdir/$sigmac-$hname > /dev/null");
|
|
|
|
$sigdat = "$sigmac-$hname";
|
|
|
|
}
|
|
|
|
elsif ($hname and ! $hnamef and $isFile )
|
|
|
|
{
|
|
|
|
system("mv $tmpdir/$sigmac- $tmpdir/$sigmac-$hname > /dev/null");
|
|
|
|
$sigdat = "$sigmac-$hname";
|
|
|
|
}
|
|
|
|
elsif (( $hnamef eq $ip) or ( $ip and ! $isFile ))
|
|
|
|
{
|
|
|
|
$sigdat = "$sigmac-$ip";
|
|
|
|
}
|
|
|
|
elsif ( $isFile and ! $hnamef and $ip )
|
|
|
|
{
|
|
|
|
system("mv $tmpdir/$sigmac- $tmpdir/$sigmac-$ip > /dev/null");
|
|
|
|
$sigdat = "$sigmac-$ip";
|
|
|
|
}
|
|
|
|
elsif ($hnamef and ! $hname )
|
|
|
|
{
|
|
|
|
$sigdat = "$sigmac-$hnamef";
|
|
|
|
}
|
|
|
|
elsif ( $hnamef and $hname and $hnamef ne $hname )
|
|
|
|
{
|
|
|
|
system("mv $tmpdir/$sigmac-$hnamef $tmpdir/$sigmac-$hname > /dev/null");
|
|
|
|
$sigdat = "$sigmac-$hname";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$sigdat = "$sigmac-";
|
|
|
|
}
|
|
|
|
|
2015-12-10 10:17:03 -07:00
|
|
|
chomp ($siglevel = `cat $sigdir/$sigmac/last_signal`) ;
|
|
|
|
if ($siglevel < -100 or $siglevel >= 0 ) { next; }
|
|
|
|
|
|
|
|
open(my $fh, '>>', "$tmpdir/$sigdat") or die "Could not open file '$tmpdir/$sigdat' $!";
|
|
|
|
print $fh "$d,$siglevel,$nf\n";
|
|
|
|
close $fh;
|
|
|
|
|
|
|
|
chomp ($lcount=`wc -l < $tmpdir/$sigdat`);
|
|
|
|
|
|
|
|
if($lcount>$MAXLINES+10)
|
|
|
|
{
|
|
|
|
$rc=`tail -n$MAXLINES $tmpdir/$sigdat > $tmpdir/$sigdat.tmp`;
|
|
|
|
$rc=`mv $tmpdir/$sigdat.tmp $tmpdir/$sigdat`;
|
|
|
|
}
|
|
|
|
}
|