I am by no means a programmer. I am just a routing and switching guy. That said, if anyone is interested, here is my script that keeps track of signal strength in the client list by mac address. Basically the customer that has this mikrotik is not willing to password protect it, but has tons of people mooching off of his connection. I crontab this to run every hour, and just do a search for a mac address in the entire directory (grep "04 B6" ./) for example. This will show me if someone has been connected for 90% of the system uptime over the course of a month...at a coffee hotspot. If so, they get the blacklist stick.
Once again, disclaimer is I am not at all a programmer, and I'm sure there are better ways to do this, but hey, hopefully this helps someone.
Output of the script will look like this:
client 5 -82
00 16 00 16 00 BB
client 4 -78
00 17 00 17 00 DD
client 3 -84
00 18 00 18 BB EF
client 2 -50
00 19 00 19 EB AB
client 1 -66
00 20 00 20 7E CC
The crontab entry would look like this:
0 */1 * * * root wirelessclients 10.248.0.1
And, the script:
#!/usr/bin/perl
wirelessclients -- a script to extract active client list from a mikrotik AP
get timestamp reference
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = $year+1900;
$mon++;
if ( $hour < 10 ) {
$hour = "0".$hour;
}
if ( $min < 10 ) {
$min = "0".$min;
}
if ( $mon < 10 ) {
$mon = "0".$mon;
}
if ( $mday < 10 ) {
$mday = "0".$mday;
}
$timestamp = $year.$mon.$mday.$hour.$min;
#init SNMP community and target MIB
$snmpro="omittedforfun";
$snmpmib="1.3.6.1.4.1.14988.1.1.1.2.1";
#user input of host IP
chomp ($rtr=$ARGV[0]);
if ( $rtr eq "" ) {die "$0: Must specify a router \n"};
congeal SNMP command into shapeless mass
$snmpwalk="/usr/local/bin/snmpwalk -v 2c -c $snmpro $rtr $snmpmib";
#open file to write to - note it will not create the dir so $rtr (user input host IP) must be manually created
open (OUT, ">/usr/local/var/log/wireless/clients/$rtr/$timestamp");
print "\n opening file /usr/local/var/log/wireless/clients/$rtr/$timestamp \n";
#execute SNMP shapeless mass and remove the MIB portion, only keeping actual data
@linewalk=$snmpwalk;
foreach $line (@linewalk) {
($mib, $hex) = split ("=", $line);
($junk, $keep) = split (/:/, $hex);
push (@linetruncate, "$keep");
}
foreach $line (@linetruncate) {
if ($line =~ m/-.*/) {
push (@db, "$line");
}
if ($line =~ m/[0-9A-Fa-f]{1,2} [0-9A-Fa-f]{1,2} [0-9A-Fa-f]{1,2} [0-9A-Fa-f]{1,2} [0-9A-Fa-f]{1,2} [0-9A-Fa-f]{1,2}/){
push (@mac, "$line");
}
}
pass array into scalar to count lines
$dbcount = @db;
$maccount = @mac;
#print line by line decrementing the counter each time
while ($dbcount > 0) {
printf (OUT "client %s %s %s \n", $dbcount, $db[-$dbcount], $mac[-$dbcount]);
$dbcount--;
}
print "\n done printing to file \n";
close OUT;