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 setUp(self): self.ap = AirodumpStation()