class TestAirodumpStation(unittest.TestCase): def setUp(self): self.ap = AirodumpStation() def test_initLoad(self): data = [ [1, '2012-05-10 11:53:54', '2012-05-10 11:53:54', 4, 5, 6, 7], [2, '2012-05-10 11:53:54', '2012-05-10 11:53:54', 4, 5, 6, 70] ] ap = AirodumpStation(data) self.assertTrue(len(ap) == 2) record = ap[0] self.assertTrue(record[0] == 1) self.assertTrue(record[6] == 7) record = ap[1] self.assertTrue(record[0] == 2) self.assertTrue(record[6] == 70) def test_set_get(self): self.ap.add([1,'2012-05-10 11:53:54','2012-05-10 11:53:54',4,5,6,7]) self.assertTrue(len(self.ap) == 1) record = self.ap[0] self.assertTrue(record[0] == 1) self.assertTrue(record[6] == 7) def test_print(self): self.ap.add([1,'2012-05-10 11:53:54','2012-05-10 11:53:54',4,5,6,7]) str(self.ap)
class TestAirodumpStation(unittest.TestCase): def setUp(self): self.ap = AirodumpStation() def test_initLoad(self): data = [[1, '2012-05-10 11:53:54', '2012-05-10 11:53:54', 4, 5, 6, 7], [2, '2012-05-10 11:53:54', '2012-05-10 11:53:54', 4, 5, 6, 70]] ap = AirodumpStation(data) self.assertTrue(len(ap) == 2) record = ap[0] self.assertTrue(record[0] == 1) self.assertTrue(record[6] == 7) record = ap[1] self.assertTrue(record[0] == 2) self.assertTrue(record[6] == 70) def test_set_get(self): self.ap.add( [1, '2012-05-10 11:53:54', '2012-05-10 11:53:54', 4, 5, 6, 7]) self.assertTrue(len(self.ap) == 1) record = self.ap[0] self.assertTrue(record[0] == 1) self.assertTrue(record[6] == 7) def test_print(self): self.ap.add( [1, '2012-05-10 11:53:54', '2012-05-10 11:53:54', 4, 5, 6, 7]) str(self.ap)
def loadCsv(in_csv_path): in_ap = False # "True" if we are in the AP's section. in_station = False # "True" if we are in the STATION's section. # Loads the input CSV file. fd = open(in_csv_path, "r") lines = fd.readlines() fd.close() # Prepare regexps. rap = re.compile('^BSSID,') rstation = re.compile('^Station MAC,') rblanck = re.compile('^\s*$') result = {'AP' : AirodumpAp(), 'STATION': AirodumpStation()} for line in lines: # Skip empty lines. if re.match(rblanck, line) != None: continue; # Detect AP header. if re.match(rap, line) != None: if in_ap: raise RuntimeError('The CSV file generated by "airodump-ng" is corrupted : duplicated "AP header" (BSSID...)! - (%s)' % line.rstrip()) if in_station: raise RuntimeError('The CSV file generated by "airodump-ng" is corrupted : "STATION header" (Station MAC...) should not appear before "AP header" (BSSID...)! - (%s)' % line.rstrip()) in_ap = True continue # Detect STATION header. if re.match(rstation, line) != None: if in_station: raise RuntimeError('The CSV file generated by "airodump-ng" is corrupted : duplicated "STATION header" (Stattion MAC...)! - (%s)' % line.rstrip()) if not in_ap: raise RuntimeError('The CSV file generated by "airodump-ng" is corrupted : "STATION header" (Stattion MAC...) should appear after "AP header" (BSSID...)! - (%s)' % line.rstrip()) in_station = True in_ap = False continue values = line.rstrip().split(',') # This is a list of values for APs. if in_ap: result['AP'].add(values) continue # This is a list of values for STATIONs. if in_station: result['STATION'].add(values) continue # This is an unexpected line. raise RuntimeError('The CSV file generated by "airodump-ng" is corrupted : unexpected line (%s)' % line.rstrip()) return result
def test_initLoad(self): data = [[1, '2012-05-10 11:53:54', '2012-05-10 11:53:54', 4, 5, 6, 7], [2, '2012-05-10 11:53:54', '2012-05-10 11:53:54', 4, 5, 6, 70]] ap = AirodumpStation(data) self.assertTrue(len(ap) == 2) record = ap[0] self.assertTrue(record[0] == 1) self.assertTrue(record[6] == 7) record = ap[1] self.assertTrue(record[0] == 2) self.assertTrue(record[6] == 70)
def getAssociatedStations(in_data, in_sort_by='iv'): aps = in_data['AP'] stations = in_data['STATION'] iv_index = AirodumpAp.index(in_sort_by) # Find all stations associated with an AP. # One station <=> one CSV record. sql = {'bssid':'^[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}$', 'probed essids':'^[a-zA-Z0-9_\.\-]+$'} associated = stations.select(sql, Csv.MATCH) # Find data for all associated APs. # One AP <=> one CSV record. best_aps = [] for station in associated: bssid = AirodumpStation.get(station, 'bssid') aps_records = aps.select({'bssid':bssid}, Csv.EQUALITY) if len(aps_records) == 0: continue # Note: We should always have len(aps_records) == 1. # Sorting is not necessary! # s = sorted(aps_records, key=lambda ap: ap[iv_index]) # best_aps.append(s[len(s)-1]) best_aps.append({'AP':aps_records[0], 'STATION':station}) return best_aps
def setUp(self): self.ap = AirodumpStation()