-
Notifications
You must be signed in to change notification settings - Fork 3
/
check_ax_clients
executable file
·97 lines (84 loc) · 1.89 KB
/
check_ax_clients
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/perl -w
# Monitor clients on Apple Airport Extreme an Express
# Requires AIRPORT-BASESTATION-3-MIB in any default SNMP MIB location
#
# Written by Darko Krizic <[email protected]>
use strict;
use Data::Dumper;
my $ax = shift;
unless ( defined $ax ) {
print "Usage: $0 <airport>\n";
exit 2;
}
my %mac;
open(SNMP,"snmpwalk -c public -v 2c -m AIRPORT-BASESTATION-3-MIB $ax SNMPv2-SMI::enterprises.apple.airport | grep wirelessPhysAddress |");
while(my $line = <SNMP>) {
chomp $line;
my ($null,$mac) = split(" = STRING: ", $line);
$mac = lc $mac;
$mac =~ s/"//g;
$mac{$mac} = {};
}
close(SNMP);
#my %arp;
open(ARP,"/usr/sbin/arp |");
<ARP>;
while(my $line = <ARP>) {
chomp $line;
my ($name,$null,$mac,$null2) = split(/ +/, $line );
if( $name =~ m/[A-Za-z]/g ) {
$name =~ s/\..+//g;
}
if( defined $mac{$mac} ) {
$mac{$mac}->{'name'} = $name;
}
}
close(ARP);
foreach( keys %mac ) {
unless( defined $mac{$_}->{'name'} ) {
$mac{$_}->{'name'} = '-';
}
}
open(WHITELIST,"/usr/local/etc/whitelist.arp");
while(my $line = <WHITELIST>) {
chomp $line;
next if $line =~ m/^$/;
next if $line =~ m/^#/;
my ($mac,$name) = split( "=", $line );
if( defined $mac{$mac} ) {
$mac{$mac}->{'whitelist'} = 1;
$mac{$mac}->{'name'} = $name;
}
}
close(WHITELIST);
my $exit = 0;
my @unknown;
my @known;
#print Dumper(\%mac);
foreach( keys %mac ) {
my $name = $mac{$_}->{'name'};
if( defined $mac{$_}->{'whitelist'} ) {
if( $name ne '-' ) {
push @known,$name;
} else {
push @known,$_;
}
} else {
push @unknown,"$name=$_";
}
}
if( scalar @unknown > 0 ) {
$exit = 1;
}
my $kcount = scalar @known;
my $ucount = scalar @unknown;
my $known = join(", ",@known);
my $unknown = join(", ",@unknown);
my $perf = "'known'=$kcount 'unknown'=$ucount;1;5";
if( $exit == 0 ) {
print "OK: $known | $perf\n";
exit 0;
} else {
print "WARNING: Unkown clients $unknown - known $known | $perf\n";
exit 1;
}