|
|
|
@ -7,12 +7,35 @@ from ttkbootstrap import ttk
|
|
|
|
|
from tkinter import messagebox
|
|
|
|
|
import re
|
|
|
|
|
from PIL import ImageTk, Image
|
|
|
|
|
import platform
|
|
|
|
|
|
|
|
|
|
from SimObjs import SimPacket, SimHost, AllSimConnect, SimRouter, SimSwitch, SimHub, SimBase
|
|
|
|
|
from dbUtil import search, execute_sql, delete_obj, truncate_db
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def round_rectangle(cv, x1, y1, x2, y2, radius=25, **kwargs):
|
|
|
|
|
points = [x1 + radius, y1,
|
|
|
|
|
x1 + radius, y1,
|
|
|
|
|
x2 - radius, y1,
|
|
|
|
|
x2 - radius, y1,
|
|
|
|
|
x2, y1,
|
|
|
|
|
x2, y1 + radius,
|
|
|
|
|
x2, y1 + radius,
|
|
|
|
|
x2, y2 - radius,
|
|
|
|
|
x2, y2 - radius,
|
|
|
|
|
x2, y2,
|
|
|
|
|
x2 - radius, y2,
|
|
|
|
|
x2 - radius, y2,
|
|
|
|
|
x1 + radius, y2,
|
|
|
|
|
x1 + radius, y2,
|
|
|
|
|
x1, y2,
|
|
|
|
|
x1, y2 - radius,
|
|
|
|
|
x1, y2 - radius,
|
|
|
|
|
x1, y1 + radius,
|
|
|
|
|
x1, y1 + radius,
|
|
|
|
|
x1, y1]
|
|
|
|
|
|
|
|
|
|
return cv.create_polygon(points, **kwargs, smooth=True)
|
|
|
|
|
|
|
|
|
|
def validate_ip_address(ip_address):
|
|
|
|
|
"""
|
|
|
|
|
匹配ip地址格式是否规范
|
|
|
|
@ -62,16 +85,16 @@ class RouterConfigWindow(tk.Toplevel):
|
|
|
|
|
def create_interface_inputs(self):
|
|
|
|
|
label_text = ["接口1", "接口2", "接口3", "接口4"]
|
|
|
|
|
for i in range(4):
|
|
|
|
|
label = tk.Label(self, text=label_text[i])
|
|
|
|
|
label = tk.Label(self, text=label_text[i], font=("黑体", 16))
|
|
|
|
|
label.grid(row=i, column=0, padx=10, pady=5, sticky="w")
|
|
|
|
|
entry = tk.Entry(self, width=20)
|
|
|
|
|
entry = tk.Entry(self, width=20, font=("黑体", 16),)
|
|
|
|
|
entry.grid(row=i, column=1, padx=10, pady=5, sticky="w")
|
|
|
|
|
self.interface_entries.append(entry)
|
|
|
|
|
button = tk.Button(self, text="添加", command=lambda index=i: self.add_router_entry(index))
|
|
|
|
|
button = tk.Button(self, text="添加", font=("黑体", 16), command=lambda index=i: self.add_router_entry(index))
|
|
|
|
|
button.grid(row=i, column=2, padx=10, pady=5)
|
|
|
|
|
lab = LabelFrame(self, text="示例")
|
|
|
|
|
lab.grid(row=4, column=0, columnspan=3, sticky=W, padx=20)
|
|
|
|
|
Label(lab, text="10.1.2.0/24 或者 10.1.2.12" if self.router_obj.ObjType == 2 else "MAC11").pack()
|
|
|
|
|
Label(lab, text="10.1.2.0/24 或者 10.1.2.12" if self.router_obj.ObjType == 2 else "MAC11", font=("黑体", 16)).pack()
|
|
|
|
|
|
|
|
|
|
def create_router_table(self):
|
|
|
|
|
def on_right_click(event):
|
|
|
|
@ -88,7 +111,10 @@ class RouterConfigWindow(tk.Toplevel):
|
|
|
|
|
self.router_treeview.delete(item)
|
|
|
|
|
self.router_table_frame = tk.Frame(self)
|
|
|
|
|
self.router_table_frame.grid(row=5, column=0, columnspan=3, padx=10, pady=5)
|
|
|
|
|
self.router_treeview = ttk.Treeview(self.router_table_frame, columns=("Interface", "Route"), show="headings")
|
|
|
|
|
style = ttk.Style()
|
|
|
|
|
style.configure("Custom.Treeview.Heading", font=("宋体", 15))
|
|
|
|
|
style.configure("Custom.Treeview", rowheight=30, font=("宋体", 15))
|
|
|
|
|
self.router_treeview = ttk.Treeview(self.router_table_frame, style="Custom.Treeview", columns=("Interface", "Route"), show="headings")
|
|
|
|
|
self.router_treeview.heading("Interface", text="接口")
|
|
|
|
|
self.router_treeview.heading("Route", text="网段")
|
|
|
|
|
self.router_treeview.pack(side="left", fill="both")
|
|
|
|
@ -203,6 +229,8 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
Image.open(sys.path[0] + "/../datas/images/集线器.png").resize((60, 60)))
|
|
|
|
|
self.host_img = ImageTk.PhotoImage(
|
|
|
|
|
Image.open(sys.path[0] + "/../datas/images/主机.png").resize((60, 60)))
|
|
|
|
|
self.width = int(self.cget("width"))
|
|
|
|
|
self.height = int(self.cget("height"))
|
|
|
|
|
self.chose = self.host_img
|
|
|
|
|
self.AllSimObjs = {}
|
|
|
|
|
self.conns = []
|
|
|
|
@ -282,6 +310,7 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
return
|
|
|
|
|
conn = AllSimConnect(self, self.line_start_obj, self.line_start_ifs, self.line_end_obj,
|
|
|
|
|
self.line_end_ifs)
|
|
|
|
|
conn.draw_line()
|
|
|
|
|
for conn_obj in self.line_start_obj.connections: # 判断两个连接对象是否已经连接过了
|
|
|
|
|
if conn_obj == conn:
|
|
|
|
|
flag = True
|
|
|
|
@ -309,15 +338,15 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
if self.drawLine:
|
|
|
|
|
self.delete("Line")
|
|
|
|
|
x, y = event.x, event.y
|
|
|
|
|
if not (150 < x < 650 and 40 < y < 490):
|
|
|
|
|
if x < 150:
|
|
|
|
|
x = 150
|
|
|
|
|
elif x > 650:
|
|
|
|
|
x = 650
|
|
|
|
|
if y < 40:
|
|
|
|
|
y = 40
|
|
|
|
|
elif y > 490:
|
|
|
|
|
y = 490
|
|
|
|
|
if not (0 < x < self.width * 0.8 and 0 < y < self.height * 0.85):
|
|
|
|
|
if x < 0:
|
|
|
|
|
x = 0
|
|
|
|
|
elif x > self.width * 0.8:
|
|
|
|
|
x = self.width * 0.8
|
|
|
|
|
if y < 0:
|
|
|
|
|
y = 0
|
|
|
|
|
elif y > self.height * 0.85:
|
|
|
|
|
y = self.height * 0.85
|
|
|
|
|
self.create_line(self.line_start_obj.ObjX, self.line_start_obj.ObjY, x + 8, y + 8, fill="#5b9bd5",
|
|
|
|
|
width=1,
|
|
|
|
|
tags="Line")
|
|
|
|
@ -345,7 +374,7 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
鼠标左键松开事件
|
|
|
|
|
:param event: 事件对象
|
|
|
|
|
"""
|
|
|
|
|
if 170 < event.x < 630 and 60 < event.y < 470: # 在方框内,无变化
|
|
|
|
|
if 20 < event.x < self.width * 0.8 + 20 and 20 < event.y < self.height * 0.85 - 20: # 在方框内,无变化
|
|
|
|
|
if name == "路由器":
|
|
|
|
|
tag = SimRouter(self, event.x, event.y)
|
|
|
|
|
elif name == "集线器":
|
|
|
|
@ -354,6 +383,7 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
tag = SimSwitch(self, event.x, event.y)
|
|
|
|
|
else:
|
|
|
|
|
tag = SimHost(self, event.x, event.y)
|
|
|
|
|
tag.create_img()
|
|
|
|
|
self.AllSimObjs[tag.ObjID] = tag
|
|
|
|
|
tag.save()
|
|
|
|
|
self.tag_bind_event()
|
|
|
|
@ -374,7 +404,7 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
else:
|
|
|
|
|
self.chose = self.host_img
|
|
|
|
|
self.delete("L")
|
|
|
|
|
if 170 < event.x < 630 and 60 < event.y < 470: # 在方框内,无变化
|
|
|
|
|
if 20 < event.x < self.width * 0.8 + 20 and 20 < event.y < self.height * 0.85 - 20: # 在方框内,无变化
|
|
|
|
|
pass
|
|
|
|
|
else: # 在方框外,显示禁止放置标识
|
|
|
|
|
self.create_oval(event.x - 10, event.y - 45, event.x + 10, event.y - 25, outline="red", width=2,
|
|
|
|
@ -410,6 +440,7 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
tag = SimSwitch(self, ObjX, ObjY, ObjID, ConfigCorrect, ObjLable)
|
|
|
|
|
else:
|
|
|
|
|
tag = SimHub(self, ObjX, ObjY, ObjID, ConfigCorrect, ObjLable)
|
|
|
|
|
tag.create_img()
|
|
|
|
|
self.AllSimObjs[tag.ObjID] = tag
|
|
|
|
|
|
|
|
|
|
sim_conn_sql = "select s.conn_id, ConfigCorrect, node_id, node_ifs from sim_conn s join conn_config c on s.conn_id=c.conn_id"
|
|
|
|
@ -423,6 +454,7 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
for key, value in conn_datas.items():
|
|
|
|
|
conn_obj = AllSimConnect(self, self.AllSimObjs[value[0][0]], value[0][1],
|
|
|
|
|
self.AllSimObjs[value[1][0]], value[1][1], key[1])
|
|
|
|
|
conn_obj.draw_line()
|
|
|
|
|
self.AllSimObjs[value[0][0]].connections[value[0][1] - 1] = conn_obj # 将连接对象传入组件对象
|
|
|
|
|
self.AllSimObjs[value[1][0]].connections[value[1][1] - 1] = conn_obj
|
|
|
|
|
self.conns.append(conn_obj)
|
|
|
|
@ -447,7 +479,9 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
if isinstance(conn, AllSimConnect):
|
|
|
|
|
conn.delete_line()
|
|
|
|
|
delete_sql = f"delete from sim_conn where conn_id in (select conn_id from conn_config where node_id='{self.chose_obj.ObjID}')"
|
|
|
|
|
delete_config_sql = f"delete from conn_config where node_id='{self.chose_obj.ObjID}'"
|
|
|
|
|
execute_sql(delete_sql)
|
|
|
|
|
execute_sql(delete_config_sql)
|
|
|
|
|
delete_obj(self.chose_obj.ObjID)
|
|
|
|
|
self.delete("rectangle")
|
|
|
|
|
self.reload_data()
|
|
|
|
@ -532,12 +566,12 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
return
|
|
|
|
|
child1 = tk.Toplevel()
|
|
|
|
|
child1.title(self.chose_obj.ObjLabel + "的标签信息")
|
|
|
|
|
child1.geometry('240x100+450+250')
|
|
|
|
|
child1.geometry('360x150+200+150')
|
|
|
|
|
child1.grab_set() # 设置组件焦点抓取。使焦点在释放之前永远保持在这个组件上,只能在这个组件上操作
|
|
|
|
|
tk.Label(child1, text='原标签:' + self.chose_obj.ObjLabel,
|
|
|
|
|
font=('黑体', 12)).grid(row=0, column=0, columnspan=2, sticky='w')
|
|
|
|
|
tk.Label(child1, text='新标签:', font=('黑体', 12)).grid(row=1, column=0, sticky='w') # ,sticky='w'靠左显示
|
|
|
|
|
new_name = tk.Entry(child1, font=('黑体', 12), textvariable=tk.StringVar())
|
|
|
|
|
font=('黑体', 16)).grid(row=0, column=0, columnspan=2, sticky='w')
|
|
|
|
|
tk.Label(child1, text='新标签:', font=('黑体', 16)).grid(row=1, column=0, sticky='w') # ,sticky='w'靠左显示
|
|
|
|
|
new_name = tk.Entry(child1, font=('黑体', 16), textvariable=tk.StringVar())
|
|
|
|
|
new_name.grid(row=1, column=1)
|
|
|
|
|
|
|
|
|
|
def update_tag():
|
|
|
|
@ -553,10 +587,10 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
child1.destroy()
|
|
|
|
|
messagebox.showinfo("提示", message="修改成功!")
|
|
|
|
|
|
|
|
|
|
tk.Button(child1, text='确定', font=('黑体', 10), height=1, command=update_tag).grid(row=2, column=0,
|
|
|
|
|
sticky='e')
|
|
|
|
|
tk.Button(child1, text='取消', font=('黑体', 10), height=1, command=child1.destroy).grid(row=2, column=1,
|
|
|
|
|
sticky='e')
|
|
|
|
|
tk.Button(child1, text='确定', font=('黑体', 16), height=1, command=update_tag).grid(row=2, column=0,
|
|
|
|
|
sticky='e', pady=10)
|
|
|
|
|
tk.Button(child1, text='取消', font=('黑体', 16), height=1, command=child1.destroy).grid(row=2, column=1,
|
|
|
|
|
sticky='e', pady=10)
|
|
|
|
|
|
|
|
|
|
def network_config(self):
|
|
|
|
|
# todo: 网络配置
|
|
|
|
@ -572,7 +606,7 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
return
|
|
|
|
|
child_r = tk.Toplevel()
|
|
|
|
|
child_r.title(self.chose_obj.ObjLabel + "的网络配置信息")
|
|
|
|
|
child_r.geometry('530x395+350+200')
|
|
|
|
|
child_r.geometry('713x522+350+200')
|
|
|
|
|
child_r.grab_set() # 设置组件焦点抓取。使焦点在释放之前永远保持在这个组件上,只能在这个组件上操作
|
|
|
|
|
ifs_frame = tk.Frame(child_r)
|
|
|
|
|
ifs_frame.grid(row=1, column=0, columnspan=4) # 装接口的框架
|
|
|
|
@ -585,20 +619,20 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
index = self.chose_obj.connections.index(conn)
|
|
|
|
|
num_label = tk.LabelFrame(ifs_frame, text=f'接口{index + 1}')
|
|
|
|
|
num_label.grid(row=num, column=0, padx=18, ipady=5)
|
|
|
|
|
tk.Label(num_label, text='MAC:', font=('黑体', 10)).grid(row=0, column=0)
|
|
|
|
|
mac_en = tk.Entry(num_label, font=('黑体', 12), textvariable=tk.StringVar(), state=DISABLED if self.chose_obj.ObjType not in [1, 2, 3] else NORMAL)
|
|
|
|
|
tk.Label(num_label, text='MAC:', font=('黑体', 16)).grid(row=0, column=0)
|
|
|
|
|
mac_en = tk.Entry(num_label, font=('黑体', 16), textvariable=tk.StringVar(), state=DISABLED if self.chose_obj.ObjType not in [1, 2, 3] else NORMAL)
|
|
|
|
|
mac_en.insert('0', str(self.chose_obj.interface[index].get("mac", "")))
|
|
|
|
|
mac_en.grid(row=0, column=1, padx=10)
|
|
|
|
|
tk.Label(num_label, text='IP:', font=('黑体', 10)).grid(row=1, column=0)
|
|
|
|
|
ip_en = tk.Entry(num_label, font=('黑体', 12), textvariable=tk.StringVar(), state=DISABLED if self.chose_obj.ObjType not in [1, 2] else NORMAL)
|
|
|
|
|
tk.Label(num_label, text='IP:', font=('黑体', 16)).grid(row=1, column=0)
|
|
|
|
|
ip_en = tk.Entry(num_label, font=('黑体', 16), textvariable=tk.StringVar(), state=DISABLED if self.chose_obj.ObjType not in [1, 2] else NORMAL)
|
|
|
|
|
ip_en.insert('0', str(self.chose_obj.interface[index].get("ip", "")))
|
|
|
|
|
ip_en.grid(row=1, column=1, padx=10)
|
|
|
|
|
tk.Label(num_label, text='端口:', font=('黑体', 10)).grid(row=0, column=2)
|
|
|
|
|
port_en = tk.Entry(num_label, font=('黑体', 12), textvariable=tk.StringVar(), state=DISABLED if self.chose_obj.ObjType != 1 else NORMAL)
|
|
|
|
|
tk.Label(num_label, text='端口:', font=('黑体', 16)).grid(row=0, column=2)
|
|
|
|
|
port_en = tk.Entry(num_label, font=('黑体', 16), textvariable=tk.StringVar(), state=DISABLED if self.chose_obj.ObjType != 1 else NORMAL)
|
|
|
|
|
port_en.insert('0', str(self.chose_obj.interface[index].get("conn_port", "")))
|
|
|
|
|
port_en.grid(row=0, column=3, padx=10)
|
|
|
|
|
tk.Label(num_label, text='应用层地址:', font=('黑体', 10)).grid(row=1, column=2)
|
|
|
|
|
addr_en = tk.Entry(num_label, font=('黑体', 12), textvariable=tk.StringVar(), state=DISABLED if self.chose_obj.ObjType != 1 else NORMAL)
|
|
|
|
|
tk.Label(num_label, text='应用层地址:', font=('黑体', 16)).grid(row=1, column=2)
|
|
|
|
|
addr_en = tk.Entry(num_label, font=('黑体', 16), textvariable=tk.StringVar(), state=DISABLED if self.chose_obj.ObjType != 1 else NORMAL)
|
|
|
|
|
addr_en.insert('0', str(self.chose_obj.interface[index].get("addr", "")))
|
|
|
|
|
addr_en.grid(row=1, column=3, padx=10)
|
|
|
|
|
num += 1
|
|
|
|
@ -606,23 +640,23 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
|
|
|
|
|
num_label = tk.LabelFrame(ifs_frame, text=f'示例')
|
|
|
|
|
num_label.grid(row=num, column=0, padx=18, ipady=5)
|
|
|
|
|
tk.Label(num_label, text='MAC:', font=('黑体', 10)).grid(row=0, column=0)
|
|
|
|
|
mac_en = tk.Entry(num_label, font=('黑体', 12), textvariable=tk.StringVar())
|
|
|
|
|
tk.Label(num_label, text='MAC:', font=('黑体', 16)).grid(row=0, column=0)
|
|
|
|
|
mac_en = tk.Entry(num_label, font=('黑体', 16), textvariable=tk.StringVar())
|
|
|
|
|
mac_en.insert('0', "MAC11")
|
|
|
|
|
mac_en.config(state=READONLY)
|
|
|
|
|
mac_en.grid(row=0, column=1, padx=10)
|
|
|
|
|
tk.Label(num_label, text='IP:', font=('黑体', 10)).grid(row=1, column=0)
|
|
|
|
|
ip_en = tk.Entry(num_label, font=('黑体', 12), textvariable=tk.StringVar())
|
|
|
|
|
tk.Label(num_label, text='IP:', font=('黑体', 16)).grid(row=1, column=0)
|
|
|
|
|
ip_en = tk.Entry(num_label, font=('黑体', 16), textvariable=tk.StringVar())
|
|
|
|
|
ip_en.insert(0, "10.1.1.10")
|
|
|
|
|
ip_en.config(state=READONLY)
|
|
|
|
|
ip_en.grid(row=1, column=1, padx=10)
|
|
|
|
|
tk.Label(num_label, text='端口:', font=('黑体', 10)).grid(row=0, column=2)
|
|
|
|
|
port_en = tk.Entry(num_label, font=('黑体', 12), textvariable=tk.StringVar())
|
|
|
|
|
tk.Label(num_label, text='端口:', font=('黑体', 16)).grid(row=0, column=2)
|
|
|
|
|
port_en = tk.Entry(num_label, font=('黑体', 16), textvariable=tk.StringVar())
|
|
|
|
|
port_en.insert('0', "80")
|
|
|
|
|
port_en.config(state=READONLY)
|
|
|
|
|
port_en.grid(row=0, column=3, padx=10)
|
|
|
|
|
tk.Label(num_label, text='应用层地址:', font=('黑体', 10)).grid(row=1, column=2)
|
|
|
|
|
addr_en = tk.Entry(num_label, font=('黑体', 12), textvariable=tk.StringVar())
|
|
|
|
|
tk.Label(num_label, text='应用层地址:', font=('黑体', 16)).grid(row=1, column=2)
|
|
|
|
|
addr_en = tk.Entry(num_label, font=('黑体', 16), textvariable=tk.StringVar())
|
|
|
|
|
addr_en.insert('0', "10.1.2.10:10810:Name3")
|
|
|
|
|
addr_en.config(state=READONLY)
|
|
|
|
|
addr_en.grid(row=1, column=3, padx=10)
|
|
|
|
@ -630,10 +664,10 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
self.chose_obj.config(datas)
|
|
|
|
|
child_r.destroy()
|
|
|
|
|
|
|
|
|
|
tk.Button(ifs_frame_YN, text='确定', font=('黑体', 10), height=1, command=commit).grid(row=0, column=0,
|
|
|
|
|
padx=20) # ,sticky="w"
|
|
|
|
|
tk.Button(ifs_frame_YN, text='取消', font=('黑体', 10), height=1,
|
|
|
|
|
command=child_r.destroy).grid(row=0, column=2, padx=20)
|
|
|
|
|
tk.Button(ifs_frame_YN, text='确定', font=('黑体', 16), height=1, command=commit).grid(row=0, column=0,
|
|
|
|
|
padx=20, pady=20) # ,sticky="w"
|
|
|
|
|
tk.Button(ifs_frame_YN, text='取消', font=('黑体', 16), height=1,
|
|
|
|
|
command=child_r.destroy).grid(row=0, column=2, padx=20, pady=20)
|
|
|
|
|
|
|
|
|
|
def router_table_config(self):
|
|
|
|
|
# todo: 路由表配置
|
|
|
|
@ -700,10 +734,10 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
messagebox.showerror("注意", message="请先选择要显示的对象!")
|
|
|
|
|
return
|
|
|
|
|
self.delete("netSet")
|
|
|
|
|
self.create_text(740, 120, text="(" + self.chose_obj.ObjLabel + ")", anchor="n", font=('微软雅黑', 10, 'bold'),
|
|
|
|
|
self.create_text(self.width * 0.82 + 120, 80, text="(" + self.chose_obj.ObjLabel + ")", anchor="n", font=('微软雅黑', 14, 'bold'),
|
|
|
|
|
fill="#7030a0", tags="netSet")
|
|
|
|
|
self.create_text(675, 145, text=self.chose_obj,
|
|
|
|
|
anchor="nw", font=('宋体', 11), tags="netSet")
|
|
|
|
|
self.create_text(self.width * 0.82 + 20, 80 + 25, text=self.chose_obj,
|
|
|
|
|
anchor="nw", font=('宋体', 14), tags="netSet")
|
|
|
|
|
|
|
|
|
|
def show_router_config(self):
|
|
|
|
|
# todo: 显示路由表交换表信息
|
|
|
|
@ -718,10 +752,10 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
messagebox.showerror("注意", message="请选择路由器/交换机对象!")
|
|
|
|
|
return
|
|
|
|
|
self.delete("routerSet")
|
|
|
|
|
self.create_text(905, 120, text="(" + self.chose_obj.ObjLabel + ")", anchor="n", font=('微软雅黑', 10, 'bold'),
|
|
|
|
|
self.create_text(self.width * 0.82 + 120, self.height * 0.85 / 2 + 50, text="(" + self.chose_obj.ObjLabel + ")", anchor="n", font=('微软雅黑', 14, 'bold'),
|
|
|
|
|
fill="#7030a0", tags="routerSet")
|
|
|
|
|
self.create_text(835, 145, text=self.chose_obj.get_table_config(),
|
|
|
|
|
anchor="nw", font=('宋体', 11), tags="routerSet")
|
|
|
|
|
self.create_text(self.width * 0.82 + 20, self.height * 0.85 / 2 + 50 + 25, text=self.chose_obj.get_table_config(),
|
|
|
|
|
anchor="nw", font=('宋体', 14), tags="routerSet")
|
|
|
|
|
|
|
|
|
|
def send_packet(self):
|
|
|
|
|
"""
|
|
|
|
@ -739,17 +773,17 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
return
|
|
|
|
|
child2 = tk.Toplevel()
|
|
|
|
|
child2.title("数据包配置")
|
|
|
|
|
child2.geometry('240x100+450+250')
|
|
|
|
|
child2.geometry('330x195+200+110')
|
|
|
|
|
child2.grab_set() # 设置组件焦点抓取。使焦点在释放之前永远保持在这个组件上,只能在这个组件上操作
|
|
|
|
|
tk.Label(child2, text='目的IP:', font=('黑体', 12)).grid(row=0, column=0, columnspan=2, sticky='w')
|
|
|
|
|
packet_ip = tk.Entry(child2, font=('黑体', 12), textvariable=tk.StringVar())
|
|
|
|
|
packet_ip.grid(row=0, column=1)
|
|
|
|
|
tk.Label(child2, text='目的MAC:', font=('黑体', 12)).grid(row=1, column=0, sticky='w') # ,sticky='w'靠左显示
|
|
|
|
|
packet_mac = tk.Entry(child2, font=('黑体', 12), textvariable=tk.StringVar())
|
|
|
|
|
packet_mac.grid(row=1, column=1)
|
|
|
|
|
tk.Label(child2, text='消息:', font=('黑体', 12)).grid(row=2, column=0, sticky='w') # ,sticky='w'靠左显示
|
|
|
|
|
packet_message = tk.Entry(child2, font=('黑体', 12), textvariable=tk.StringVar())
|
|
|
|
|
packet_message.grid(row=2, column=1)
|
|
|
|
|
tk.Label(child2, text='目的IP:', font=('黑体', 16)).grid(row=0, column=0, columnspan=2, sticky='w', pady=10)
|
|
|
|
|
packet_ip = tk.Entry(child2, font=('黑体', 16), textvariable=tk.StringVar())
|
|
|
|
|
packet_ip.grid(row=0, column=1, pady=10)
|
|
|
|
|
tk.Label(child2, text='目的MAC:', font=('黑体', 16)).grid(row=1, column=0, sticky='w', pady=10) # ,sticky='w'靠左显示
|
|
|
|
|
packet_mac = tk.Entry(child2, font=('黑体', 16), textvariable=tk.StringVar())
|
|
|
|
|
packet_mac.grid(row=1, column=1, pady=10)
|
|
|
|
|
tk.Label(child2, text='消息:', font=('黑体', 16)).grid(row=2, column=0, sticky='w', pady=10) # ,sticky='w'靠左显示
|
|
|
|
|
packet_message = tk.Entry(child2, font=('黑体', 16), textvariable=tk.StringVar())
|
|
|
|
|
packet_message.grid(row=2, column=1, pady=10)
|
|
|
|
|
|
|
|
|
|
def send():
|
|
|
|
|
"""
|
|
|
|
@ -773,9 +807,8 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
packet_message.get())
|
|
|
|
|
child2.destroy()
|
|
|
|
|
|
|
|
|
|
tk.Button(child2, text='确定', font=('黑体', 10), height=1, command=send).grid(row=3, column=0, sticky='e')
|
|
|
|
|
tk.Button(child2, text='取消', font=('黑体', 10), height=1, command=child2.destroy).grid(row=3, column=1,
|
|
|
|
|
sticky='e')
|
|
|
|
|
tk.Button(child2, text='确定', font=('黑体', 16), height=1, command=send).grid(row=3, column=0, sticky='e', pady=10)
|
|
|
|
|
tk.Button(child2, text='取消', font=('黑体', 16), height=1, command=child2.destroy).grid(row=3, column=1, sticky='e', pady=10)
|
|
|
|
|
|
|
|
|
|
def send_packet_list(self):
|
|
|
|
|
"""
|
|
|
|
@ -788,26 +821,26 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
hosts[tag.ObjLabel] = tag.ObjID
|
|
|
|
|
child2 = tk.Toplevel()
|
|
|
|
|
child2.title("批量数据包配置")
|
|
|
|
|
child2.geometry('400x420+450+200')
|
|
|
|
|
tk.Label(child2, text='目的IP:', font=('黑体', 12)).grid(row=0, column=0, columnspan=2, sticky='w', ipady=10)
|
|
|
|
|
packet_ip = tk.Entry(child2, font=('黑体', 12), textvariable=tk.StringVar())
|
|
|
|
|
child2.geometry('462x452+200+110')
|
|
|
|
|
tk.Label(child2, text='目的IP:', font=('黑体', 16)).grid(row=0, column=0, columnspan=2, sticky='w', ipady=10)
|
|
|
|
|
packet_ip = tk.Entry(child2, font=('黑体', 16), textvariable=tk.StringVar())
|
|
|
|
|
packet_ip.grid(row=0, column=1, pady=5)
|
|
|
|
|
tk.Label(child2, text='目的MAC:', font=('黑体', 12)).grid(row=1, column=0, sticky='w',
|
|
|
|
|
tk.Label(child2, text='目的MAC:', font=('黑体', 16)).grid(row=1, column=0, sticky='w',
|
|
|
|
|
pady=5) # ,sticky='w'靠左显示
|
|
|
|
|
packet_mac = tk.Entry(child2, font=('黑体', 12), textvariable=tk.StringVar())
|
|
|
|
|
packet_mac = tk.Entry(child2, font=('黑体', 16), textvariable=tk.StringVar())
|
|
|
|
|
packet_mac.grid(row=1, column=1, pady=5)
|
|
|
|
|
tk.Label(child2, text='消息:', font=('黑体', 12)).grid(row=2, column=0, sticky='w', pady=5) # ,sticky='w'靠左显示
|
|
|
|
|
packet_message = tk.Entry(child2, font=('黑体', 12), textvariable=tk.StringVar())
|
|
|
|
|
tk.Label(child2, text='消息:', font=('黑体', 16)).grid(row=2, column=0, sticky='w', pady=5) # ,sticky='w'靠左显示
|
|
|
|
|
packet_message = tk.Entry(child2, font=('黑体', 16), textvariable=tk.StringVar())
|
|
|
|
|
packet_message.grid(row=2, column=1, pady=5)
|
|
|
|
|
host = StringVar()
|
|
|
|
|
tk.Label(child2, text='发送主机:', font=('黑体', 12)).grid(row=3, column=0, sticky='w',
|
|
|
|
|
tk.Label(child2, text='发送主机:', font=('黑体', 16)).grid(row=3, column=0, sticky='w',
|
|
|
|
|
pady=5) # ,sticky='w'靠左显示
|
|
|
|
|
combobox = ttk.Combobox(
|
|
|
|
|
master=child2, # 父容器
|
|
|
|
|
height=5, # 高度,下拉显示的条目数量
|
|
|
|
|
width=12, # 宽度
|
|
|
|
|
state='readonly', # readonly(只可选)
|
|
|
|
|
font=('', 18), # 字体
|
|
|
|
|
font=('', 16), # 字体
|
|
|
|
|
textvariable=host, # 通过StringVar设置可改变的值
|
|
|
|
|
values=list(hosts.keys()), # 设置下拉框的选项
|
|
|
|
|
)
|
|
|
|
@ -856,10 +889,10 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
threading.Thread(target=data[0].send, args=(data[1],)).start()
|
|
|
|
|
child2.destroy()
|
|
|
|
|
|
|
|
|
|
tk.Button(child2, text="添加数据包", font=('黑体', 12), height=3, command=add).grid(row=0, column=2, rowspan=4)
|
|
|
|
|
tk.Button(child2, text="添加数据包", font=('黑体', 14), height=3, command=add).grid(row=0, column=2, rowspan=4, padx=10)
|
|
|
|
|
button_frame = Frame(child2)
|
|
|
|
|
tk.Button(button_frame, text="发送", font=('黑体', 12), height=1, command=send).pack(side=RIGHT, padx=20)
|
|
|
|
|
tk.Button(button_frame, text="取消", font=('黑体', 12), height=1, command=child2.destroy).pack(side=RIGHT)
|
|
|
|
|
tk.Button(button_frame, text="发送", font=('黑体', 16), height=1, command=send).pack(side=RIGHT, padx=20)
|
|
|
|
|
tk.Button(button_frame, text="取消", font=('黑体', 16), height=1, command=child2.destroy).pack(side=RIGHT)
|
|
|
|
|
button_frame.grid(row=6, column=0, columnspan=3)
|
|
|
|
|
|
|
|
|
|
def clear_canvas(self):
|
|
|
|
@ -886,20 +919,21 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
创建整体页面布局
|
|
|
|
|
:return:
|
|
|
|
|
"""
|
|
|
|
|
self.create_rectangle(150, 40, 650, 490, outline="#7f6000", width=3) # 矩形框,左上角坐标,右下角坐标
|
|
|
|
|
self.create_rectangle(660, 100, 815, 400, outline="#ffff00", width=3, fill="#f4b88e") # 矩形框,左上角坐标,右下角坐标
|
|
|
|
|
self.create_text(735, 105, text="网络配置信息", anchor="n", font=('微软雅黑', 11, 'bold'))
|
|
|
|
|
self.create_rectangle(825, 100, 1000, 400, outline="#ffff00", width=3, fill="#f4b88e") # 矩形框,左上角坐标,右下角坐标
|
|
|
|
|
self.create_text(915, 105, text="路由/交换表信息", anchor="n", font=('微软雅黑', 11, 'bold'))
|
|
|
|
|
self.create_rectangle(0, 0, self.width * 0.8, self.height * 0.85, outline="#7f6000", width=3) # 矩形框,左上角坐标,右下角坐标
|
|
|
|
|
round_rectangle(self, self.width * 0.82, 30, self.width * 0.98, self.height * 0.85 / 2 - 30, outline="#ffff00", width=3, fill="#f4b88e") # 矩形框,左上角坐标,右下角坐标
|
|
|
|
|
self.create_text(self.width * 0.82 + 120, 30 + 15, text="网络配置信息", anchor="n", font=('微软雅黑', 18, 'bold'))
|
|
|
|
|
round_rectangle(self, self.width * 0.82, self.height * 0.85 / 2, self.width * 0.98, self.height * 0.85 - 30, outline="#ffff00", width=2, fill="#f4b88e") # 矩形框,左上角坐标,右下角坐标
|
|
|
|
|
self.create_text(self.width * 0.82 + 120, self.height * 0.85 / 2 + 15, text="路由/交换表信息", anchor="n", font=('微软雅黑', 18, 'bold'))
|
|
|
|
|
# 显示左边的固定图片
|
|
|
|
|
self.create_text(80 - 55, 120 + 15, text="路由器", anchor="nw", font=('微软雅黑', 14, 'bold')) # 显示文字
|
|
|
|
|
router = self.create_image(80, 120, image=self.router_img, anchor="nw")
|
|
|
|
|
self.create_text(80 - 55, 190 + 15, text="交换机", anchor="nw", font=('微软雅黑', 14, 'bold')) # 显示文字
|
|
|
|
|
switch = self.create_image(80, 190, image=self.switch_img, anchor="nw")
|
|
|
|
|
self.create_text(80 - 55, 260 + 15, text="集线器", anchor="nw", font=('微软雅黑', 14, 'bold')) # 显示文字
|
|
|
|
|
hub = self.create_image(80, 260, image=self.hub_img, anchor="nw")
|
|
|
|
|
self.create_text(80 - 55, 330 + 15, text="主机", anchor="nw", font=('微软雅黑', 14, 'bold')) # 显示文字
|
|
|
|
|
host = self.create_image(80, 330, image=self.host_img, anchor="nw")
|
|
|
|
|
img_height, text_height, split_width = self.height - 120, self.height - 60, 120
|
|
|
|
|
self.create_text(split_width, text_height, text="路由器", anchor="nw", font=('微软雅黑', 18, 'bold')) # 显示文字
|
|
|
|
|
router = self.create_image(split_width, img_height, image=self.router_img, anchor="nw")
|
|
|
|
|
self.create_text(split_width * 2, text_height, text="交换机", anchor="nw", font=('微软雅黑', 18, 'bold')) # 显示文字
|
|
|
|
|
switch = self.create_image(split_width * 2, img_height, image=self.switch_img, anchor="nw")
|
|
|
|
|
self.create_text(split_width * 3, text_height, text="集线器", anchor="nw", font=('微软雅黑', 18, 'bold')) # 显示文字
|
|
|
|
|
hub = self.create_image(split_width * 3, img_height, image=self.hub_img, anchor="nw")
|
|
|
|
|
self.create_text(split_width * 4, text_height, text="主机", anchor="nw", font=('微软雅黑', 18, 'bold')) # 显示文字
|
|
|
|
|
host = self.create_image(split_width * 4, img_height, image=self.host_img, anchor="nw")
|
|
|
|
|
self.bind_event(router, "路由器")
|
|
|
|
|
self.bind_event(switch, "交换机")
|
|
|
|
|
self.bind_event(hub, "集线器")
|
|
|
|
@ -941,14 +975,15 @@ class NetWorkAnalog(Canvas):
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
root = Window()
|
|
|
|
|
root.title('网络拓扑图')
|
|
|
|
|
width = 1030
|
|
|
|
|
height = 530 # 窗口大小
|
|
|
|
|
screen_width = root.winfo_screenwidth() # winfo方法来获取当前电脑屏幕大小
|
|
|
|
|
screen_height = root.winfo_screenheight()
|
|
|
|
|
x = int((screen_width - width) / 2)
|
|
|
|
|
y = int((screen_height - height) / 2) - 40
|
|
|
|
|
size = '{}x{}+{}+{}'.format(width, height, x, y)
|
|
|
|
|
canvas = NetWorkAnalog(root, width=1030, heigh=height, bg="white")
|
|
|
|
|
root_attr = {
|
|
|
|
|
"width": screen_width * 0.83,
|
|
|
|
|
"height": screen_height * 0.85,
|
|
|
|
|
}
|
|
|
|
|
size = '%dx%d+%d+%d' % (root_attr['width'], root_attr['height'], (screen_width - root_attr['width']) / 2,
|
|
|
|
|
(screen_height - root_attr['height']) / 2 - 30)
|
|
|
|
|
canvas = NetWorkAnalog(root, width=root_attr['width'], heigh=root_attr['height'], bg="white")
|
|
|
|
|
canvas.place(x=0, y=0, anchor='nw')
|
|
|
|
|
root.geometry(size)
|
|
|
|
|
root.mainloop()
|
|
|
|
|