代码拉取完成,页面将自动刷新
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()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。