1 Star 3 Fork 0

cengsiming/pcaptool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
demo.py 4.43 KB
一键复制 编辑 原始数据 按行查看 历史
cengsiming 提交于 2024-09-28 10:58 . update
import ttkbootstrap as ttk
import copy
class Fliter_page:
def __init__(self):
self.window2 = ttk.Window(
title='条件规则',
)
self.filterrule_dict={'源IP':[],'目的IP':[],'源端口':[],'目的端口':[],'传输层协议':['TCP','UDP','ICMP','SCTP'],'MAC地址':[],'VLANID':[]}
self.filterrule_dict2 ={'源IP':'sourceIp','目的IP':'destIp','源端口':'sourcePort','目的端口':'destPort','传输层协议':'ipProtocol','MAC地址':'macAddress','VLANID':'vlanId'}
self.filterrule_dict3={"sourceIp":[],"destIp":[],"sourcePort":[],"destPort":[],"ipProtocol":[],"macAddress":[],"vlanId":[]}
self.filterrule_list = []
self.n=0
self.frame_list=[]
self.filter_text_list=[]
self.fileter_result = []
self.add_filter_frame()
def switch_eq(self,eq_noteq):
if eq_noteq['text']=='=':
eq_noteq.configure(text='!=')
else:
eq_noteq.configure(text='=')
def filter_select(self,filter_rule,filter_value):
select_value = self.filterrule_dict[filter_rule.get()]
if not select_value:
filter_value.configure()
filter_value.configure(values=[''],state='normal')
filter_value.current(0)
else:
filter_value.configure(values=select_value,state='readonly')
filter_value.current(0)
def add_current_text(self,text1,filter_rule,eq_noteq,filter_value,n):
if eq_noteq["text"]=='=':
self.filterrule_list[n][self.filterrule_dict2[filter_rule.get()]].append(filter_value.get())
# self.filterrule_dict3[self.filterrule_dict2[filter_rule.get()]].append(filter_value.get())
else:
self.filterrule_list[n][self.filterrule_dict2[filter_rule.get()]].append(f'NOT_{filter_value.get()}')
# self.filterrule_dict3[self.filterrule_dict2[filter_rule.get()]].append(f'NOT_{filter_value.get()}')
text1.delete('0.0','end')
text1.insert('end',self.filterrule_list[n])
def finish(self):
try:
# print(self.filter_text_list[0].get('0.0','end'))
# self.fileter_result=self.filter_text_list[0].get('0.0','end')#self.filter_text_list可能为空
for i in self.filter_text_list:
self.fileter_result.append(eval(i.get('0.0','end').strip()))
except:
...
self.window2.destroy()
print(self.fileter_result)
def delete_filter_frame(self,frame1):
frame1.destroy()
self.frame_list.pop()
self.filter_text_list.pop()
def add_filter_frame(self):
n = self.n
self.n += 1
self.filterrule_list.append(copy.deepcopy(self.filterrule_dict3))
frame1=ttk.Labelframe(self.window2,text='条件类型',width=405,height=175)
frame1.pack()
self.frame_list.append(frame1)
text1=ttk.Text(frame1,width=54,height=5)
self.filter_text_list.append(text1)
text1.place(x=5,y=45)
filter_rule = ttk.Combobox(frame1,bootstyle="primay",width=10 ,state='readonly', values=list(self.filterrule_dict.keys()))
filter_rule.current(0)
filter_rule.place(x=10,y=0)
# eq_noteq=ttk.Button(frame1)
eq_noteq=ttk.Button(frame1,text='=',width=2,command=lambda:self.switch_eq(eq_noteq))
eq_noteq.place(x=108,y=0)
filter_value = ttk.Combobox(frame1,bootstyle="primay",width=20)
filter_value.place(x=147,y=0)
filter_rule.bind("<<ComboboxSelected>>", lambda x:self.filter_select(filter_rule,filter_value)) # 绑定事件
add_button=ttk.Button(frame1,text='+ 添加',command=lambda:self.add_current_text(text1,filter_rule,eq_noteq,filter_value,n))
add_button.place(x=336,y=0)
def lay(self):
self.frame_bottom=ttk.Frame(self.window2,)
self.frame_bottom.pack(side='bottom')
self.add_frame_Button=ttk.Button(self.frame_bottom,text='+ 添加规则',command=self.add_filter_frame)
self.add_frame_Button.pack(side='left',padx=20)
self.add_frame_Button=ttk.Button(self.frame_bottom,bootstyle='danger',text='- 删除规则',command=lambda :self.delete_filter_frame(self.frame_list[-1]))
self.add_frame_Button.pack(side='left',padx=20)
finish_button=ttk.Button(self.frame_bottom,text='完成',command=self.finish)
finish_button.pack(side='left',padx=20)
self.window2.mainloop()
if __name__ == '__main__':
ad=Fliter_page()
ad.lay()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/cengsiming/pcaptool.git
git@gitee.com:cengsiming/pcaptool.git
cengsiming
pcaptool
pcaptool
master

搜索帮助