-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathap-client-list-engenius.py
executable file
·188 lines (149 loc) · 4.88 KB
/
ap-client-list-engenius.py
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/python
import time
import re
from colorama import Style, Fore, Back
import paramiko
from pysnmp.hlapi import *
aps = ["ap-downstairs", "ap-upstairs", "ap-test"]
username = "admin"
password = "FIXME"
snmpcomm = "FIXME"
# Just a file mapping mac address to short names:
#
# b8:27:eb:01:02:03 pi-test
#
macfile = "/usr/local/etc/internal-macs.txt"
# Read in internal mac file
hostdb = {}
try:
with open(macfile) as macs:
for line in macs:
(key, val) = line.split()
hostdb[key] = val
except EnvironmentError:
print 'Problem reading file', macfile, "!"
# Start with a blank line
print
# iterate aps
for host in aps:
# Initialize client counters
count2g = 0
count5g = 0
# All this to get the SNMP location natively :(
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
CommunityData(snmpcomm),
UdpTransportTarget((host, 161)),
ContextData(),
ObjectType(ObjectIdentity('1.3.6.1.2.1.1.6.0')))
)
if errorIndication:
print(errorIndication)
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
else:
location = varBinds[0][1]
# Print current host, location
print '%-20s (%s)' % (host, location)
print "===================================================================="
# Begin SSH portion
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host, port=22, username=username, password=password, timeout=5)
channel = client.get_transport().open_session()
channel.invoke_shell()
# Get 2ghz channels
channel.send('stat info channel2\n')
while not channel.recv_ready():
time.sleep(.5)
chan2gout = channel.recv(9999)
chan2lines = chan2gout.splitlines()
# Get 5ghz channels
channel.send('stat info channel5\n')
while not channel.recv_ready():
time.sleep(.5)
chan5gout = channel.recv(9999)
chan5lines = chan5gout.splitlines()
# Get 2ghz clients
channel.send('stat client2 kickclient\n')
while not channel.recv_ready():
time.sleep(.5)
client2gout = channel.recv(9999)
client2lines = client2gout.splitlines()
# Get 5ghz clients
channel.send('stat client5 kickclient\n')
while not channel.recv_ready():
time.sleep(.5)
client5gout = channel.recv(9999)
client5lines = client5gout.splitlines()
# Close session
client.close()
# Process 2g channels
for line in chan2lines:
if "Current" in line:
line = line.strip()
words = line.split()
channel2g = words[1]
# Process 5g channels
for line in chan5lines:
if "Current" in line:
line = line.strip()
words = line.split()
channel5g = words[1]
# Print channels, more header misc.
# Current frequencies: Chan. X Chan. 5
print ("Current frequencies: " + Fore.CYAN + "Chan. %s Chan. %s" % (channel2g, channel5g)),
print Style.RESET_ALL
print "--------------------------------------------------------------------"
print "Client MAC RSSI"
print "--------------------------------------------------------------------"
# Process / print 2g clients
for line in client2lines:
if re.search("^SSID[0-9]+", line):
line = line.strip()
words = line.split()
mac = words[1]
cmac = Fore.YELLOW + mac + Style.RESET_ALL
# Have to futz with RSSI :(
rssi = words[4]
rssi = rssi.lstrip('-')
rssi = int(rssi)
rssi = (100 - rssi)
rssi = str(rssi)
crssi = Fore.BLUE + rssi + Style.RESET_ALL
if mac in hostdb.keys():
client = hostdb[mac]
cclient = Fore.MAGENTA + client + Style.RESET_ALL
else:
client = "UNKNOWN"
cclient = Fore.RED + client + Style.RESET_ALL
print '%-32s %-28s %-4s' % (cclient, cmac, crssi)
count2g += 1
# Process / print 5g clients
for line in client5lines:
if re.search("^SSID[0-9]+", line):
line = line.strip()
words = line.split()
mac = words[1]
cmac = Fore.YELLOW + mac + Style.RESET_ALL
# Have to futz with RSSI :(
rssi = words[4]
rssi = rssi.lstrip('-')
rssi = int(rssi)
rssi = (100 - rssi)
rssi = str(rssi)
crssi = Fore.BLUE + rssi + Style.RESET_ALL
if mac in hostdb.keys():
client = hostdb[mac]
cclient = Fore.MAGENTA + client + Style.RESET_ALL
else:
client = "UNKNOWN"
cclient = Fore.RED + client + Style.RESET_ALL
print '%-32s %-28s %-4s' % (cclient, cmac, crssi)
count5g +=1
# No clients connected...
if ((count2g == 0) and (count5g == 0)):
print "NO CLIENTS"
# Blank seperator line
print