-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDump_CSV_Divider.py
More file actions
69 lines (49 loc) · 2.02 KB
/
Dump_CSV_Divider.py
File metadata and controls
69 lines (49 loc) · 2.02 KB
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
import pandas as pd
import numpy as np
import os
def delete_blanks(file_name):
with open(file_name, 'r') as f:
lines = f.readlines()
# remove spaces
lines = [line.replace(' ', '') for line in lines]
# finally, write lines in the file
with open(file_name, 'w') as f:
f.writelines(lines)
def keep_cols(in_file_name, out_file_name, keep_col):
f = pd.read_csv(in_file_name)
new_f = f[keep_col]
new_f.to_csv(out_file_name, index=False)
def split_dump(dump, networks_file_name, clients_file_name):
file = open(dump, "r")
networks_file = open("files/%s_raw.csv" % networks_file_name, "w+")
clients_file = open("files/%s_raw.csv" % clients_file_name, "w+")
x = 0
for line in file:
if x == 1:
networks_file.write(line)
elif x == 2:
clients_file.write(line)
if line == "\n":
x += 1
def process_dump(dump_name):
csv_file = dump_name
networks_name = "networks"
clients_name = "clients"
clients_keep_cols = ["Station MAC", " BSSID"]
networks_keep_cols = ["BSSID", " channel", " ESSID"]
split_dump(csv_file, networks_name, clients_name)
keep_cols("files/%s_raw.csv" % networks_name, "files/networks.csv", networks_keep_cols)
keep_cols("files/%s_raw.csv" % clients_name, "files/clients.csv", clients_keep_cols)
clients = pd.read_csv("files/clients.csv", skipinitialspace=True)
networks = pd.read_csv("files/networks.csv", skipinitialspace=True).rename(columns={"channel": "Channel"})
result = clients.merge(networks, on="BSSID", how="left")
result["Device_Name"] = np.nan
result.to_csv("files/dump.csv", index=False)
networks = pd.read_csv("files/networks.csv", skipinitialspace=True)
networks.to_csv("files/networks.csv")
os.remove("files/%s_raw.csv" % networks_name)
os.remove("files/%s_raw.csv" % clients_name)
os.remove("files/%s.csv" % clients_name)
# os.remove("files/%s.csv" % networks_name)
return "files/dump.csv"
process_dump("test-01._csv")