def __init__(self): self.aps = defaultdict() self.clients = defaultdict() self.channel_list = [] self.soft_mac_list = ['2','3','6','7','A','B','E','F'] output_raw = commands.getoutput('cat /tmp/atear-scan-01.csv') output = output_raw.split("\n") for out in output: match = re.match( r"([0-9A-Fa-f]{2,2}:[0-9A-Fa-f]{2,2}:[0-9A-Fa-f]{2,2}:[0-9A-Fa-f]{2,2}:[0-9A-Fa-f]{2,2}:[0-9A-Fa-f]{2,2})\s*,\s*\d{4,4}-\d{2,2}-\d{2,2}\s*\d{2,2}:\d{2,2}:\d{2,2}\s*,\s*(\d{4,4}-\d{2,2}-\d{2,2}\s*\d{2,2}:\d{2,2}:\d{2,2})\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\w+)\s*,\s*([\w\s]*)\s*,\s*(\w*)\s*,\s*(.\d+)\s*,\s*\d+\s*,\s*(\d+)\s*,.+,\s*(.+)\s*,.*", out) if match: company = db_reader.oui_search(str(match.group(1))) if str(match.group(1))[1] in self.soft_mac_list: ap_type = 'SoftAp' elif int(match.group(8)) == -1: ap_type = 'ad-hoc', else: ap_type = 'Access Point' self.aps[match.group(1)] = { 'type' : ap_type, 'company':company, 'product' : 'unknown', 'nd_beacons': 0, 'sid_length' : 0, 'Time': match.group(2), 'ch': match.group(3), "enc": match.group(5), 'cipher': match.group(6), 'auth': match.group(7), 'power':match.group(8), 'nb_data': match.group(9), 'essid':match.group(10), 'bssid':match.group(1), } else: matchb = re.match( r"([0-9A-Fa-f]{2,2}:[0-9A-Fa-f]{2,2}:[0-9A-Fa-f]{2,2}:[0-9A-Fa-f]{2,2}:[0-9A-Fa-f]{2,2}:[0-9A-Fa-f]{2,2})\s*,\s*\d{4,4}-\d{2,2}-\d{2,2}\s*\d{2,2}:\d{2,2}:\d{2,2}\s*,\s*(\d{4,4}-\d{2,2}-\d{2,2}\s*\d{2,2}:\d{2,2}:\d{2,2})\s*,\s*(.\d+)\s*,\s*(\d+)\s*,\s*(.+)\s*,.*", out) if not matchb: continue else: if "WPA" in matchb.group(5) or "OPN" in matchb.group(5) or "WEP" in matchb.group( 5) or "WPA2" in matchb.group(5): pass else: company = db_reader.oui_search(str(matchb.group(1))) sta_type = 'station' if int(matchb.group(3)) == -1: sta_type = 'ad-hoc' sta_bssid = str(matchb.group(1)).upper() ap_bssid = str(matchb.group(5)).upper() if "NOT ASSOCIATED" in ap_bssid: ap_bssid = 'notasso' duplicated_flag = False if sta_bssid in self.aps: duplicated_flag = True self.clients[sta_bssid] = { 'bssid':sta_bssid, 'essid': ' ', 'type': sta_type, 'Time': str(matchb.group(2)), "nb_data": str(matchb.group(4)), 'probes': ' ', 'power': str(matchb.group(3)), 'company': company, 'duplicated': duplicated_flag, }
def __init__(self): self._networks = defaultdict(dict) self._clients = defaultdict(dict) self.soft_ap = False soft_mac_list = ['2', '3', '6', '7', 'A', 'B', 'E', 'F'] # Copy and remove \x00 character. scan_result_file = './log/air_scan_result' + '-01.csv' # 'airodump' add a number such as -01 when save the file. new_csv_file = './log/air_scan_result.csv' tmp_csv = open(scan_result_file, 'rb') scanned_data = tmp_csv.read() tmp_csv.close() new_csv = open(new_csv_file, 'wb') new_csv.write(scanned_data.replace('\x00', '')) new_csv.close() with open(new_csv_file, 'rU') as f: parsing_networks = True for line in csv.reader(f): if not line or line[0] == 'BSSID': continue if line[0] == 'Station MAC': parsing_networks = False continue line = map(str, line) if parsing_networks: company = db_reader.oui_search(line[0]) if line[0][1] in soft_mac_list: self.soft_ap = True try: self[line[0]].update({ 'company': company, 'product': db_reader.product_search(line[0]), 'essid': line[13][1:], 'bssid': line[0], 'ch': int(line[3]), 'power': int(line[8]), 'enc': line[5] + line[6], 'Time': line[2], 'nb_data': int(line[10]), 'nb_beacons': int(line[9]), 'sid_length': int(line[12]), }) except: pass try: if self.soft_ap: self[line[0]].update({ 'type': 'SoftAp', }) self.soft_ap = False elif line[8] == -1: self[line[0]].update({ 'type': 'ad-hoc', }) else: self[line[0]].update({ 'type': 'Access Point', }) except: pass else: try: sta_type = 'station' if int(line[3]) == -1: sta_type = 'ad-hoc' self._clients[line[0]].update({ 'type': sta_type, 'bssid': line[0], 'Time': line[2], 'essid': line[5].strip(), 'power': int(line[3]), 'nb_data': line[4], 'probes': line[6].split(', '), 'company': db_reader.oui_search(line[0]), 'product': db_reader.product_search(line[0]), }) except: pass
def __init__(self): self._networks = defaultdict(dict) self._clients = defaultdict(dict) self.soft_ap = False soft_mac_list = ['2', '3', '6', '7', 'A', 'B', 'E', 'F'] tmp_csv = open('/tmp/atear-01.csv', 'rb') data = tmp_csv.read() tmp_csv.close() new_csv = open('/tmp/atear.csv', 'wb') new_csv.write(data.replace('\x00', '')) new_csv.close() csv_path = '/tmp/atear.csv' with open(csv_path, 'rU') as f: parsing_networks = True for line in csv.reader(f): if not line or line[0] == 'BSSID': continue if line[0] == 'Station MAC': parsing_networks = False continue line = map(str, line) if parsing_networks: company = db_reader.oui_search(line[0]) if line[0][1] in soft_mac_list: self.soft_ap = True try: self[line[0]].update({ 'company': company, 'product': db_reader.product_search(line[0]), 'essid': line[13][1:], 'bssid': line[0], 'ch': int(line[3]), 'power': int(line[8]), 'enc': line[5] + line[6], 'Time': line[2], 'nb_data': int(line[10]), 'nb_beacons': int(line[9]), 'sid_length': int(line[12]), }) except: pass try: if self.soft_ap: self[line[0]].update({ 'type': 'SoftAp', }) self.soft_ap = False elif line[8] == -1: self[line[0]].update({ 'type': 'ad-hoc', }) else: self[line[0]].update({ 'type': 'Access Point', }) except: pass else: try: sta_type = 'station' if int(line[3]) == -1: sta_type = 'ad-hoc' self._clients[line[0]].update({ 'type': sta_type, 'bssid': line[0], 'Time': line[2], 'essid': line[5].strip(), 'power': int(line[3]), 'nb_data': line[4], 'probes': line[6].split(', '), 'company': db_reader.oui_search(line[0]), 'product': db_reader.product_search(line[0]), }) except: pass