From af37e48d66b4fa23298c7ee98b21edab141d93a9 Mon Sep 17 00:00:00 2001 From: Jed Reynolds Date: Thu, 4 Jun 2020 22:49:17 -0700 Subject: [PATCH] stations_connected.py: provides method to query how many stations are associated with BSSID --- py-scripts/stations_connected.py | 40 ++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/py-scripts/stations_connected.py b/py-scripts/stations_connected.py index 5076b8f2..a64d5df0 100755 --- a/py-scripts/stations_connected.py +++ b/py-scripts/stations_connected.py @@ -12,20 +12,46 @@ if 'py-json' not in sys.path: sys.path.append('../py-json') from LANforge.lfcli_base import LFCliBase +from realm import Realm +import pprint +from pprint import pprint - -class QueryStationsExample(LFCliBase): +class StationsConnected(LFCliBase): def __init__(self, lfjson_host, lfjson_port): - super().__init__(_lfjson_host=lfjson_host, _lfjson_port=lfjson_port, _halt_on_error=True, _debug=True) + super().__init__(_lfjson_host=lfjson_host, _lfjson_port=lfjson_port, _halt_on_error=True, _debug=False) + self.localrealm = Realm(lfclient_host=lfjson_host, lfclient_port=lfjson_port, debug=False) + self.check_connect() def run(self): - pass + self.clear_test_results() + fields = "_links,port,alias,ip,ap,port+type" + self.station_results = self.localrealm.find_ports_like("sta*", fields, debug_=False) + #pprint(self.station_results) + if (self.station_results is None) or (len(self.station_results) < 1): + self.get_failed_result_list() + return False + return True + def num_associated(self, bssid): + counter = 0 + # print("there are %d results" % len(self.station_results)) + for eid,record in self.station_results.items(): + #print("-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ") + #pprint(eid) + #pprint(record) + if record["ap"] == bssid: + counter += 1 + #print("-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ") + return counter def main(): - qstationsx = QueryStationsExample("localhost", 8080) - qstationsx.run() - + qstationsx = StationsConnected("localhost", 8080) + bssid = "00:0E:8E:7B:DF:9B" + if qstationsx.run(): + associated_stations = qstationsx.num_associated(bssid) + print("Number of stations associated to %s: %s" % (bssid, associated_stations)) + else: + print("problem querying for stations for %s" % bssid) if __name__ == "__main__": main()