加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ap.py 2.77 KB
一键复制 编辑 原始数据 按行查看 历史
Deyao Yang 提交于 2020-12-23 02:25 . replace pathlib to os
import os
import json
import pandas as pd
DATA_FILE = 'scan_report.csv'
MANAGER_SSIDS = ['02:19:be:a3:2a:155', '02:19:be:a3:2a:131', '02:19:be:a3:2a:143', '02:19:be:a3:2a:167', '02:19:be:a3:2a:138',
'02:19:be:a3:2a:87', '02:19:be:a3:2a:117', '02:19:be:a3:2a:134', '02:19:be:a3:2a:135', '02:19:be:a3:2a:160', ]
MANAGER_CHANNELS = [34, 12, 19, 21, 22, 23, 24]
def to_json2(df, key=None, orient='records'):
df_json = df.to_json(orient = orient, force_ascii = False)
df_json = json.loads(df_json)
if key is not None:
df_json = {key: df_json}
return df_json
class DataManager(object):
def __init__(self, csv_file) -> None:
super().__init__()
assert os.path.exists(csv_file), "CSV file not exists!"
self.df = pd.read_csv(csv_file)
def __repr__(self):
return str(self.df.info())
def get_total_cnt(self):
return len(self.df)
def get_total_channel_cnt(self):
return len(set(self.df['channel']))
def get_all_bssids(self):
return list(self.df['bssid'])
def get_filtered_bssid_cnt(self, lib_bssids):
filtered_bssids = []
filtered_channels = []
for bssid in self.df['bssid']:
if bssid not in lib_bssids:
filtered_bssids.append(bssid)
filtered_channels.append(int(self.df[self.df['bssid']==bssid]['channel']))
bssid_cnt = len(filtered_bssids)
channel_cnt = len(set(filtered_channels))
return bssid_cnt, channel_cnt
# def get_filtered_channel_cnt(self, lib_channel):
# cnt = 0
# for channel in self.df['channel']:
# if channel not in lib_channel:
# cnt += 1
# return cnt
def quiry_engine(self, cond: str, result_file: str, key: str='result', indent: int=3):
name, value = cond.replace(' ', '').split('==')
if name not in self.df:
return False
result = self.df[self.df[name]==value]
json_result = to_json2(self.df, key)
with open(result_file, 'w+') as f:
json.dump(json_result, f, indent=indent)
return True
def main():
dm = DataManager(DATA_FILE)
total_cnt = dm.get_total_cnt()
channel_cnt = dm.get_total_channel_cnt()
bssids = dm.get_all_bssids()
rogue_entry_cnt, rogue_entry_channel_cnt = dm.get_filtered_bssid_cnt(MANAGER_SSIDS)
# channel_rogue_entry_cnt = dm.get_filtered_channel_cnt(MANAGER_CHANNELS)
dm.quiry_engine('channel==36', 'dmypy.json', None)
print('all bssids: ')
from pprint import pprint
pprint(bssids)
print('total_cnt: ', total_cnt)
print('channel_cnt: ', channel_cnt)
print('rogue entry cnt: ', rogue_entry_cnt)
print('rogue entry channel cnt: ', rogue_entry_channel_cnt)
if __name__ == '__main__':
main()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化