diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml
index ba6eba2..427aed5 100644
--- a/.idea/dataSources.xml
+++ b/.idea/dataSources.xml
@@ -1,24 +1,12 @@
-
+
sqlite.xerial
true
org.sqlite.JDBC
- jdbc:sqlite:$PROJECT_DIR$/../网络仿真/NetworkAnalog/network.db
+ jdbc:sqlite:$PROJECT_DIR$/NetworkAnalog/network.db
$ProjectFileDir$
-
- sqlite.xerial
- true
- org.sqlite.JDBC
- jdbc:sqlite:D:\头哥\NetworkAnalog\datas\network.db
- $ProjectFileDir$
-
-
- file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.40.1/org/xerial/sqlite-jdbc/3.40.1.0/sqlite-jdbc-3.40.1.0.jar
-
-
-
\ No newline at end of file
diff --git a/NetworkAnalog/NetworkAnalog.py b/NetworkAnalog/NetworkAnalog.py
index 3ab7bcc..c28b3a4 100644
--- a/NetworkAnalog/NetworkAnalog.py
+++ b/NetworkAnalog/NetworkAnalog.py
@@ -205,7 +205,7 @@ class NetWorkAnalog(Canvas):
for tag_id, tag in self.AllSimObjs.items():
self.tag_bind(tag.ObjID, "", lambda event, tag=tag: show_menu(event, tag)) # 绑定右击事件
- def bind_event(self, component, name):
+ def add_sim_obj(self, component, name):
# todo: 绑定事件
"""
绑定事件
@@ -305,9 +305,9 @@ class NetWorkAnalog(Canvas):
conn_obj.ConfigCorrect = key[1]
self.tag_bind_event()
- def show_obj(self, AllSimObj, conns):
+ def show_obj(self, AllSimObj, AllSimConn):
self.AllSimObjs = AllSimObj
- self.conns = conns
+ self.conns = AllSimConn
for key, sim_obj in self.AllSimObjs.items():
sim_obj.create_img()
for conn in self.conns:
@@ -517,7 +517,7 @@ class NetWorkAnalog(Canvas):
addr_en.grid(row=1, column=3, padx=10)
def commit():
self.chose_obj.config(datas)
- self.message.show_message(f"组件 {self.chose_obj} 网络配置成功!")
+ self.message.show_message(f"组件 {self.chose_obj.ObjLabel} 网络配置成功!")
child_r.destroy()
tk.Button(ifs_frame_YN, text='确定', font=('黑体', 16), height=1, command=commit).grid(row=0, column=0,
@@ -855,42 +855,50 @@ class NetWorkAnalog(Canvas):
sticky='e', pady=10)
def create_config_button(self):
+ font_size = 16
+ font_style = ("Arial", font_size)
+ style = ttk.Style()
+ style.configure("TMenubutton", font=font_style)
# 创建一个菜单栏,这里我们可以把他理解成一个容器,在窗口的上方
- menubar = tk.Menu(root)
+ menubar = tk.Menu(root, font=font_style)
# 定义一个空菜单单元
- setMenu = tk.Menu(menubar, tearoff=0)
- menubar.add_cascade(label='删除与修改', menu=setMenu)
+ setMenu = tk.Menu(menubar, tearoff=0, font=font_style)
+ menubar.add_cascade(label='删除与修改', menu=setMenu, font=font_style)
setMenu.add_command(label='删除对象', command=self.delete_obj)
setMenu.add_command(label='删除连接线', command=self.delete_line)
setMenu.add_command(label='修改标签', command=self.update_tag_name)
# # 定义一个空菜单单元
- setMenu = tk.Menu(menubar, tearoff=0)
- menubar.add_cascade(label='基础配置', menu=setMenu)
+ setMenu = tk.Menu(menubar, tearoff=0, font=font_style)
+ menubar.add_cascade(label='基础配置', menu=setMenu, font=font_style)
setMenu.add_command(label='网络配置', command=self.network_config)
setMenu.add_command(label='路由表配置', command=self.router_table_config)
setMenu.add_command(label='交换表配置', command=self.mac_table_config)
root.config(menu=menubar)
# 定义一个空菜单单元
- setMenu = tk.Menu(menubar, tearoff=0)
- menubar.add_cascade(label='显示设置', menu=setMenu)
+ setMenu = tk.Menu(menubar, tearoff=0, font=font_style)
+ menubar.add_cascade(label='显示设置', menu=setMenu, font=font_style)
setMenu.add_command(label='显示/不显示标签', command=self.show_label)
setMenu.add_command(label='显示/不显示接口', command=self.show_interface)
setMenu.add_command(label='显示网络配置信息', command=self.show_network_config)
setMenu.add_command(label='显示路由/交换表信息', command=self.show_router_config)
# 定义一个空菜单单元
- setMenu = tk.Menu(menubar, tearoff=0)
- menubar.add_cascade(label='发送数据包', menu=setMenu)
+ setMenu = tk.Menu(menubar, tearoff=0, font=font_style)
+ menubar.add_cascade(label='发送数据包', menu=setMenu, font=font_style)
setMenu.add_command(label='发送数据包', command=self.send_packet)
setMenu.add_command(label='批量发送数据包', command=self.send_packet_list)
- menubar.add_command(label='清除屏幕', command=self.clear_canvas)
- menubar.add_command(label='导出数据', command=self.export_data)
- menubar.add_command(label='导入数据', command=self.import_data)
- menubar.add_command(label='校验', command=self.check_network)
+ menubar.add_command(label='清除屏幕', command=self.clear_canvas, font=font_style)
+ menubar.add_command(label='导出数据', command=self.export_data, font=font_style)
+ menubar.add_command(label='导入数据', command=self.import_data, font=font_style)
+ menubar.add_command(label='校验', command=self.check_network, font=font_style)
+ # 设置字体大小
+ for menu in menubar.winfo_children():
+ menu.config(font=font_style)
+ for item in menu.winfo_children():
+ item.config(font=font_style)
root.config(menu=menubar)
def create_widget(self):
- # todo: 创建页面
"""
创建整体页面布局
:return:
@@ -911,10 +919,10 @@ class NetWorkAnalog(Canvas):
hub = self.create_image(img_height, split_width * 3, image=self.hub_img, anchor="nw")
self.create_text(text_height, split_width * 4 + 40, text="主机", anchor="nw", font=('微软雅黑', 18, 'bold')) # 显示文字
host = self.create_image(img_height, split_width * 4, image=self.host_img, anchor="nw")
- self.bind_event(router, "路由器")
- self.bind_event(switch, "交换机")
- self.bind_event(hub, "集线器")
- self.bind_event(host, "主机")
+ self.add_sim_obj(router, "路由器")
+ self.add_sim_obj(switch, "交换机")
+ self.add_sim_obj(hub, "集线器")
+ self.add_sim_obj(host, "主机")
if __name__ == '__main__':
diff --git a/NetworkAnalog/SimObjs.py b/NetworkAnalog/SimObjs.py
index 4eedab3..bf08d68 100644
--- a/NetworkAnalog/SimObjs.py
+++ b/NetworkAnalog/SimObjs.py
@@ -303,9 +303,17 @@ class AllSimConnect():
nodex_update_sql = f"""
update conn_config set
ip='{node.interface[ifs - 1]["ip"]}',
- mac='{node.interface[ifs - 1]["mac"]}',
- conn_port='{node.interface[ifs - 1]["conn_port"]}',
- addr='{node.interface[ifs - 1]["addr"]}'
+ mac='{node.interface[ifs - 1]["mac"]}'
+ """
+ if not node.interface[ifs - 1]["conn_port"] == "NULL":
+ nodex_update_sql += f"""
+ ,conn_port='{int(node.interface[ifs - 1]["conn_port"])}'
+ """
+ if not node.interface[ifs - 1]["addr"] == "NULL":
+ nodex_update_sql += f"""
+ ,addr='{node.interface[ifs - 1]["addr"]}'
+ """
+ nodex_update_sql += f"""
where node_id='{node.ObjID}' and node_ifs={ifs}
"""
execute_sql(nodex_update_sql)
@@ -319,7 +327,8 @@ class AllSimConnect():
"""
execute_sql(update_sql)
except Exception as E:
- pass
+ print(E)
+ self.canvas.message.show_message(f"{E}")
def check_config(self):
"""
diff --git a/NetworkAnalog/network.db b/NetworkAnalog/network.db
index 6f4a422..e774764 100644
Binary files a/NetworkAnalog/network.db and b/NetworkAnalog/network.db differ
diff --git a/NetworkAnalog/test.py b/NetworkAnalog/test.py
new file mode 100644
index 0000000..ba86c48
--- /dev/null
+++ b/NetworkAnalog/test.py
@@ -0,0 +1,21 @@
+from sqlalchemy import create_engine
+
+engine = create_engine("mysql+pymysql://root:123123@127.0.0.1:3306/test")
+import pandas as pd
+import pymysql
+
+conn = pymysql.connect(host="127.0.0.1",
+ port=3306,
+ user="root",
+ password="123123")
+# 获取游标
+cursor = conn.cursor()
+cursor.execute("create database test;")
+conn.commit()
+
+data: pd.DataFrame = pd.read_excel("step1/data.xlsx")
+data.to_sql("test", con=engine)
+
+cursor.execute("use test")
+cursor.execute("select * from test")
+print(cursor.fetchall())
diff --git a/NetworkAnalog/tkTest.py b/NetworkAnalog/tkTest.py
deleted file mode 100644
index f8174ae..0000000
--- a/NetworkAnalog/tkTest.py
+++ /dev/null
@@ -1,34 +0,0 @@
-import sqlite3
-import pandas as pd
-import os
-
-import xlwt
-from PIL import Image
-
-
-class ExportUtil():
- def __init__(self, path):
- self.conn = sqlite3.connect('./network.db')
- self.path = path
-
- def get_table_names(self):
- cursor = self.conn.cursor()
- cursor.execute("SELECT name FROM sqlite_master WHERE type='table';") # 如果你使用SQLite数据库
- tables = cursor.fetchall()
- cursor.close()
- return [table[0] for table in tables]
-
- def export(self):
- tables = self.get_table_names()
- with pd.ExcelWriter(self.path, engine='openpyxl') as writer:
- for table in tables:
- table_name = table
- # a. 从数据库中获取表的数据并存储在DataFrame中
- query = f"SELECT * FROM {table_name}"
- df = pd.read_sql(query, self.conn)
- # b. 使用Pandas将数据写入Excel文件的不同sheet中
- df.to_excel(writer, sheet_name=table_name, index=False)
-
-export = ExportUtil("./data.xlsx")
-export.export()
-
diff --git a/NetworkAnalog/x1_test.py b/NetworkAnalog/x1_test.py
index 115e7f5..3fd1106 100644
--- a/NetworkAnalog/x1_test.py
+++ b/NetworkAnalog/x1_test.py
@@ -1,18 +1,43 @@
-from tkinter import Tk
-from NetworkAnalog import *
-from SimObjs import *
-if __name__ == '__main__':
- Tk()
- AllSimObjs = {}
- host1 = SimHost(None, 50, 100)
- AllSimObjs[host1.ObjID] = host1
- host2 = SimHost(None, 200, 100)
- AllSimObjs[host2.ObjID] = host2
- router = SimRouter(None, 100, 100)
- AllSimObjs[router.ObjID] = router
+AllSimObj = [
+ {"ObjID": "SHO1", "ObjType": 1, "ObjLabel": "A", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
+ {"ObjID": "SHO2", "ObjType": 1, "ObjLabel": "B", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
+ {"ObjID": "SHO3", "ObjType": 1, "ObjLabel": "C", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
+ {"ObjID": "SHO4", "ObjType": 1, "ObjLabel": "D", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
+ {"ObjID": "SHO5", "ObjType": 1, "ObjLabel": "E", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
+ {"ObjID": "SHO6", "ObjType": 1, "ObjLabel": "F", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
+ {"ObjID": "SHO7", "ObjType": 1, "ObjLabel": "G", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
+ {"ObjID": "SHO8", "ObjType": 1, "ObjLabel": "H", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
+ {"ObjID": "SRO1", "ObjType": 2, "ObjLabel": "R1", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
+ {"ObjID": "SRO2", "ObjType": 2, "ObjLabel": "R2", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
+ {"ObjID": "SRO3", "ObjType": 2, "ObjLabel": "R3", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
+ {"ObjID": "SRO4", "ObjType": 2, "ObjLabel": "R4", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
+ {"ObjID": "SRO5", "ObjType": 2, "ObjLabel": "R5", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
+ {"ObjID": "SRO6", "ObjType": 2, "ObjLabel": "R6", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
+ {"ObjID": "SRO7", "ObjType": 2, "ObjLabel": "R7", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
+ {"ObjID": "SWO1", "ObjType": 3, "ObjLabel": "S1", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
+ {"ObjID": "SHub1", "ObjType": 4, "ObjLabel": "Hub1", "ObjX": 100, "ObjY": 100, "ConfigCorrect": 0},
+]
- host1_router_connect = AllSimConnect(None, host1, 1, router, 1)
- host2_router_connect = AllSimConnect(None, host2, 1, router, 2)
+AllSimConn = [
+ {"ConnObjID": "conn1", "NobjS": "SHO1", "IfsS": 1, "NobjE": "SRO1", "IfsE": 1, "ConfigCorrect": 0},
+ {"ConnObjID": "conn1", "NobjS": "SHO2", "IfsS": 1, "NobjE": "SRO1", "IfsE": 2, "ConfigCorrect": 0},
+ {"ConnObjID": "conn1", "NobjS": "SRO2", "IfsS": 1, "NobjE": "SRO1", "IfsE": 4, "ConfigCorrect": 0},
+ {"ConnObjID": "conn1", "NobjS": "SWO1", "IfsS": 1, "NobjE": "SRO1", "IfsE": 3, "ConfigCorrect": 0},
+ {"ConnObjID": "conn1", "NobjS": "SHO2", "IfsS": 1, "NobjE": "SWO1", "IfsE": 2, "ConfigCorrect": 0},
+ {"ConnObjID": "conn1", "NobjS": "SRO2", "IfsS": 2, "NobjE": "SRO4", "IfsE": 1, "ConfigCorrect": 0},
+ {"ConnObjID": "conn1", "NobjS": "SRO2", "IfsS": 3, "NobjE": "SRO3", "IfsE": 1, "ConfigCorrect": 0},
+ {"ConnObjID": "conn1", "NobjS": "SRO3", "IfsS": 2, "NobjE": "SRO4", "IfsE": 2, "ConfigCorrect": 0},
+ {"ConnObjID": "conn1", "NobjS": "SRO3", "IfsS": 3, "NobjE": "SRO5", "IfsE": 1, "ConfigCorrect": 0},
+ {"ConnObjID": "conn1", "NobjS": "SRO4", "IfsS": 4, "NobjE": "SHO5", "IfsE": 1, "ConfigCorrect": 0},
+ {"ConnObjID": "conn1", "NobjS": "SRO4", "IfsS": 3, "NobjE": "SRO5", "IfsE": 2, "ConfigCorrect": 0},
+ {"ConnObjID": "conn1", "NobjS": "SRO5", "IfsS": 3, "NobjE": "SHO6", "IfsE": 1, "ConfigCorrect": 0},
+ {"ConnObjID": "conn1", "NobjS": "SRO5", "IfsS": 4, "NobjE": "SRO6", "IfsE": 2, "ConfigCorrect": 0},
+ {"ConnObjID": "conn1", "NobjS": "SRO6", "IfsS": 3, "NobjE": "SHO3", "IfsE": 2, "ConfigCorrect": 0},
+ {"ConnObjID": "conn1", "NobjS": "SRO6", "IfsS": 1, "NobjE": "SRO7", "IfsE": 2, "ConfigCorrect": 0},
+ {"ConnObjID": "conn1", "NobjS": "SRO7", "IfsS": 1, "NobjE": "SHub1", "IfsE": 1, "ConfigCorrect": 0},
+ {"ConnObjID": "conn1", "NobjS": "SRO7", "IfsS": 3, "NobjE": "SHO4", "IfsE": 1, "ConfigCorrect": 0},
+ {"ConnObjID": "conn1", "NobjS": "SHub1", "IfsS": 2, "NobjE": "SHO4", "IfsE": 1, "ConfigCorrect": 0},
+]
diff --git a/NetworkAnalog/x2_test.py b/NetworkAnalog/x2_test.py
deleted file mode 100644
index 978c0c5..0000000
--- a/NetworkAnalog/x2_test.py
+++ /dev/null
@@ -1,33 +0,0 @@
-from NetworkAnalog import NetWorkAnalog
-from SimObjs import *
-
-
-
-if __name__ == '__main__':
- AllSimObj = {}
- root = Window()
- root.title('网络拓扑图')
- root_attr = {
- "width": root.winfo_screenwidth() * 0.83,
- "height": root.winfo_screenheight() * 0.85,
- }
- size = '%dx%d+%d+%d' % (root_attr['width'], root_attr['height'], (root.winfo_screenwidth() - root_attr['width']) / 2,
- (root.winfo_screenheight() - 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)
- host1 = SimHost(canvas, 406, 268)
- AllSimObj[host1.ObjID] = host1
- host2 = SimHost(canvas, 323, 285)
- AllSimObj[host2.ObjID] = host2
- router = SimRouter(canvas, 216, 263)
- AllSimObj[router.ObjID] = router
- host1_router_connect = AllSimConnect(canvas, host1, 1, router, 1)
- host2_router_connect = AllSimConnect(canvas, host2, 1, router, 2)
- host1.connections[0] = host1_router_connect
- router.connections[0] = host1_router_connect
- host2.connections[0] = host2_router_connect
- router.connections[1] = host2_router_connect
- conns = [host1_router_connect, host2_router_connect]
- canvas.show_obj(AllSimObj, conns)
- root.mainloop()
\ No newline at end of file