diff --git a/Internet/__pycache__/data_crud.cpython-39.pyc b/Internet/__pycache__/data_crud.cpython-39.pyc new file mode 100644 index 0000000..37c09c1 Binary files /dev/null and b/Internet/__pycache__/data_crud.cpython-39.pyc differ diff --git a/Internet/__pycache__/data_crud_sqlite.cpython-39.pyc b/Internet/__pycache__/data_crud_sqlite.cpython-39.pyc new file mode 100644 index 0000000..be8fcb8 Binary files /dev/null and b/Internet/__pycache__/data_crud_sqlite.cpython-39.pyc differ diff --git a/Internet/__pycache__/data_detail.cpython-39.pyc b/Internet/__pycache__/data_detail.cpython-39.pyc new file mode 100644 index 0000000..822b1d5 Binary files /dev/null and b/Internet/__pycache__/data_detail.cpython-39.pyc differ diff --git a/Internet/__pycache__/data_dispose_CR.cpython-39.pyc b/Internet/__pycache__/data_dispose_CR.cpython-39.pyc new file mode 100644 index 0000000..f80acbf Binary files /dev/null and b/Internet/__pycache__/data_dispose_CR.cpython-39.pyc differ diff --git a/Internet/__pycache__/data_envelop.cpython-39.pyc b/Internet/__pycache__/data_envelop.cpython-39.pyc new file mode 100644 index 0000000..a4d0926 Binary files /dev/null and b/Internet/__pycache__/data_envelop.cpython-39.pyc differ diff --git a/Internet/__pycache__/data_line.cpython-39.pyc b/Internet/__pycache__/data_line.cpython-39.pyc new file mode 100644 index 0000000..bef0ce2 Binary files /dev/null and b/Internet/__pycache__/data_line.cpython-39.pyc differ diff --git a/Internet/__pycache__/main_X4.cpython-39.pyc b/Internet/__pycache__/main_X4.cpython-39.pyc new file mode 100644 index 0000000..b3f28ed Binary files /dev/null and b/Internet/__pycache__/main_X4.cpython-39.pyc differ diff --git a/Internet/data_crud.py b/Internet/data_crud.py new file mode 100644 index 0000000..c0b4b11 --- /dev/null +++ b/Internet/data_crud.py @@ -0,0 +1,143 @@ +# 导入模块 +import pymysql + + +# 连接本地数据库 +db = pymysql.connect( + host='localhost', # 例:127.0.0.1 本地数据库地址 + port=3306, # 端口号 + user='root', # 用户id + passwd='123456', # 用户密码 + db='demodb' # 连接的数据库 +) +cursor = db.cursor() +# print(cursor) + + + +# 设置查找simhost表的函数 +def get_simhost_alldata(): + # 获取simhost数据库中所有的数据 + sql = ''' + select * from simhost + ''' + cursor.execute(sql) + # 获取全部数据 + test = cursor.fetchall() + # test = pd.read_sql(sql,db) + host_data_all = [] + for i in test: + # 在这里对数据进行整理... + ID = i[0] + ObjID = i[1] + ObjType = i[2] + ObjLable = i[3] + IPAddr = i[4] + ObjX = i[5] + ObjY = i[6] + MACAddr = i[7] + ObjShow = i[8] + host_data = { + 'ID': ID, + 'ObjID': ObjID, + 'ObjType': ObjType, + 'ObjLable': ObjLable, + 'IPAddr': IPAddr, + 'ObjX': ObjX, + 'ObjY': ObjY, + 'MACAddr': MACAddr, + 'ObjShow': ObjShow + } + host_data_all.append(host_data) + # print(host_data) + # print(test) # 错误 + # cursor.close() # 关闭游标 + # db.close() # 关闭数据库连接 + return host_data_all + +# 建立条件查询将ObjShow==1的值全部获取 +def Select_ObjShow(): + sql = '''select * from simhost where ObjShow=1''' + cursor.execute(sql) + objshow_select = cursor.fetchall() + # print(objshow_select) + objshow_select_all = [] + for i in objshow_select: + # 在这里对数据进行整理... + ID = i[0] + ObjID = i[1] + ObjType = i[2] + ObjLable = i[3] + IPAddr = i[4] + ObjX = i[5] + ObjY = i[6] + MACAddr = i[7] + ObjShow = i[8] + host_data = { + 'ID': ID, + 'ObjID': ObjID, + 'ObjType': ObjType, + 'ObjLable': ObjLable, + 'IPAddr': IPAddr, + 'ObjX': ObjX, + 'ObjY': ObjY, + 'MACAddr': MACAddr, + 'ObjShow': ObjShow + } + objshow_select_all.append(host_data) + # print(objshow_select_all) + return objshow_select_all + +# 设置联合查询ipAddr的地址 +def select_and_ip(id): + data_all = [] + sql = '''select ipaddr.ipaddr from ipaddr inner join simhost on ipaddr.sim_id = simhost.id where simhost.id=%s''' + cursor.execute(sql,id) + data = cursor.fetchall() + for item in data: + # print(item[0]) + data_all.append(item[0]) + + # print(data_all) + return data_all + + +# 创建查询ObjLable列的函数 +def select_ObjLable(): + data_all = [] + sql = ''' + select objlable from simhost + ''' + cursor.execute(sql) + test = cursor.fetchall() + for item in test: + data_all.append(item[0]) + # print(data_all) + return data_all + + +# 在这个位置添加一个修改objshow列的数据函数 +def reve_objshow(): + # 将所有的对象全转换为objshow = 0 + sql = '''update simhost set objshow = 0 where objshow = 1''' + cursor.execute(sql) + db.commit() + return None + + +def reve_after(after_data): + # 将获取的数据进行循环 + for item in after_data: + sql = '''update simhost set objshow = 1 where objlable = %s''' + cursor.execute(sql, item) + db.commit() + return None + + + +if __name__ == '__main__': + # print(get_simhost_alldata()) + # print(select_ObjLable()) + reve_objshow() + after_data = ['A','R1','B'] + reve_after(after_data) \ No newline at end of file diff --git a/Internet/data_crud_sqlite.py b/Internet/data_crud_sqlite.py new file mode 100644 index 0000000..ffb3acc --- /dev/null +++ b/Internet/data_crud_sqlite.py @@ -0,0 +1,197 @@ +# 尝试用sqlite3数据库试试 +import sqlite3 +conn = sqlite3.connect('internet.db') +cursor = conn.cursor() + +# 设置创建数据库的函数 +def create_simhost(): + sql = '''DROP TABLE IF EXISTS `simhost`''' + cursor.execute(sql) + sql_simhost = '''CREATE TABLE simhost + ( + id integer primary key , + ObjID varchar(20), + ObjType int, + Objlable varchar(20), + IPAddr varchar(64), + ObjX int, + ObjY int, + MACAddr varchar(64), + ObjShow int + );''' + cursor.execute(sql_simhost) + return None + +#建立数据表ipaddr的函数 +def create_ipaddr(): + sql = '''DROP TABLE IF EXISTS `ipaddr`''' + cursor.execute(sql) + sql_ipaddr = '''CREATE TABLE ipaddr + ( + id integer primary key , + ipaddr varchar(25), + sim_id int, + foreign key (sim_id) references simhost(id) + );''' + cursor.execute(sql_ipaddr) + return None + +# 设置两个插入数据函数 +def insert_simhost(): + # 需要插入的数据 + data_simhost = [ + (1, 'SH01', 1, 'A', '101.11.1.2', 170, 120, 'MAC01', 1), + (2, 'SR01', 2, 'R1', '102.10.1.1', 250, 160, 'MAC02', 1), + (3, 'SR02', 2, 'R2', '102.10.5.1', 370, 130, 'MAC03', 1), + (4, 'SR03', 2, 'R4', '102.10.6.1', 400, 200, 'MAC04', 1), + (5, 'SR04', 2, 'R5', '111.12.1.1', 480, 260, 'MAC05', 1), + (6, 'SH02', 1, 'D', '201.21.1.2', 420, 330, 'MAC06', 1), + (7, 'SHO3', 1, 'B', '101.11.1.8', 250, 240, 'MAC07', 0), + (8, 'SR05', 2, 'R3', '102.10.6.2', 520, 160, 'MAC08', 0), + (9, 'SH04', 1, 'C', '201.21.1.5', 540, 320, 'MAC09', 0), + ] + sql = '''INSERT INTO simhost (id,ObjID,ObjType,Objlable,IPAddr,ObjX,ObjY,MACAddr,ObjShow) + VALUES (?,?,?,?,?,?,?,?,?)''' + cursor.executemany(sql,data_simhost) + conn.commit() + return None + +def insert_ipaddr(): + # 需要插入的数据 + data_ipaddr = [ + (1, '101.11.1.1', 1), + (2, '102.10.1.1', 2), + (3, '102.10.5.1', 3), + (4, '111.12.5.1', 4), + (5, '201.21.1.1', 5), + ] + sql = '''INSERT INTO ipaddr (id,ipaddr,sim_id) VALUES (?,?,?)''' + cursor.executemany(sql,data_ipaddr) + conn.commit() + return None + +# 设置获取数据库中所有数据的函数 +def get_simhost_alldata(): + sql = '''SELECT * FROM simhost''' + cursor.execute(sql) + data = cursor.fetchall() + # print(data) + all_data = [] + for item in data: + ID = item[0]; ObjID = item[1]; ObjType = item[2] + ObjLable = item[3]; IPAddr = item[4]; ObjX = item[5] + ObjY = item[6]; MACAddr = item[7]; ObjShow = item[8] + host_data = { + 'ID': ID,'ObjID': ObjID,'ObjType': ObjType, + 'ObjLable': ObjLable,'IPAddr': IPAddr,'ObjX': ObjX, + 'ObjY': ObjY,'MACAddr': MACAddr,'ObjShow': ObjShow + } + all_data.append(host_data) + return all_data + +# 建立条件查询将ObjShow==1的值全部取出 +def Select_ObjShow(): + sql = '''SELECT * FROM simhost WHERE ObjShow=1''' + cursor.execute(sql) + objshow_data = cursor.fetchall() + # print(objshow_data) + objshow_data_all = [] + for item in objshow_data: + ID = item[0]; ObjID = item[1]; ObjType = item[2] + ObjLable = item[3]; IPAddr = item[4]; ObjX = item[5] + ObjY = item[6]; MACAddr = item[7]; ObjShow = item[8] + host_data = { + 'ID': ID,'ObjID': ObjID,'ObjType': ObjType, + 'ObjLable': ObjLable,'IPAddr': IPAddr,'ObjX': ObjX, + 'ObjY': ObjY,'MACAddr': MACAddr,'ObjShow': ObjShow + } + objshow_data_all.append(host_data) + return objshow_data_all + +# 建立联合查询ipaddr的地址 +def select_and_ip(id): + data_all = [] + sql = '''SELECT ipaddr.ipaddr FROM ipaddr INNER JOIN simhost ON ipaddr.sim_id = simhost.id WHERE simhost.id=?''' + cursor.execute(sql, (id,)) + data = cursor.fetchall() + for item in data: + # print(item[0]) + data_all.append(item[0]) + return data_all + +# 建立查询ObjLable列的函数 +def select_ObjLable(): + data_all = [] + sql = '''SELECT objlable FROM simhost''' + cursor.execute(sql) + data = cursor.fetchall() + for item in data: + data_all.append(item[0]) + # print(data_all) + return data_all + +# 建立这个位置添加一个修改objshow列的数据函数 +def reve_objshow(): + sql = '''UPDATE simhost SET objshow=0 WHERE objshow=1''' + cursor.execute(sql) + conn.commit() + return None + +# 建立一个修改指定数据的函数objshow +def reve_after(after_data): + # 将获取的数据进行循环 + for item in after_data: + sql = '''UPDATE simhost SET objshow=1 WHERE objlable=?''' + cursor.execute(sql, (item,)) + conn.commit() + return None + + +# 建立一个通过查询ObjLable并返回ObjID的函数 +def select_ObjLable_ObjID(objlable): + sql = '''SELECT objx,objy,objid,objshow FROM simhost WHERE objlable=?''' + cursor.execute(sql, (objlable,)) + old_data = cursor.fetchall() + new_data = old_data[0] + # print(new_data) + return new_data + +# 建立函数通过指定的ObjID来查找所有的数据 +def Select_ObjID(array): + array_all_data = [] # 用来获取所有的对应的数据并放入其中 + sql = '''SELECT * FROM simhost WHERE objlable=?''' + for item in array: + cursor.execute(sql, (item,)) + data = cursor.fetchall() + # print(data) + ID = data[0][0];ObjID = data[0][1];ObjType = data[0][2] + ObjLable = data[0][3];IPAddr = data[0][4];ObjX = data[0][5] + ObjY = data[0][6];MACAddr = data[0][7];ObjShow = data[0][8] + host_data = { + 'ID': ID, 'ObjID': ObjID, 'ObjType': ObjType, + 'ObjLable': ObjLable, 'IPAddr': IPAddr, 'ObjX': ObjX, + 'ObjY': ObjY, 'MACAddr': MACAddr, 'ObjShow': ObjShow + } + array_all_data.append(host_data) + return array_all_data + + + +if __name__ == '__main__': + # create_simhost() + # insert_simhost() + # create_ipaddr() + # insert_ipaddr() + # get_data_sinhost() + # print(get_simhost_alldata()) + # print(Select_ObjShow()) + # print(select_and_ip(1)) + # print(select_ObjLable()) + # reve_objshow() + # after_data = ['A', 'R1', 'B'] + # reve_after(after_data) + # select_ObjLable_ObjID('A') + # array = ['A','B'] + # print(Select_ObjID(array)) + pass + diff --git a/Internet/data_detail.py b/Internet/data_detail.py new file mode 100644 index 0000000..224192d --- /dev/null +++ b/Internet/data_detail.py @@ -0,0 +1,117 @@ +# 在这个文件里画出详情 + + +# 创建函数用来画出详情 +import time + + +class Detail_Show(): + def __init__(self, cv, img_detail, move_data): + self.cv = cv + self.move_data = move_data + self.img_detail = img_detail + + def show_detail(self): + # time.sleep(5) + self.detail_data_all = [] + # 通过获取的move_data数据来画出详情表 + for item in self.move_data: + detail_data_x = item[0]+20 + detail_data_y = item[1] + detail_type = item[3] + detail_data = (detail_data_x,detail_data_y,detail_type) + self.detail_data_all.append(detail_data) + self.cv.create_image(detail_data_x,detail_data_y, image=self.img_detail, tags='detail') # 完成 + + return self.detail_data_all + + +# 建立一个用来画出详情的类 + +class Show_green_detail(): + def __init__(self, cv, item): + self.cv = cv + self.item = item + + # 建立画出对象详情的函数 + def draw_detail(self): + # 判断type对象来画出详情表 + if self.item[2] == 1: # 当type对象为1 画出主机详情图 + # 在这里画出详情图 + frist_x = self.item[0] # 获取frist_x + frist_y = self.item[1] # 获取frist_y + # 这里缺少一个删除其他详情的步骤 + # 画出连接详情表的线 + self.cv.delete('line') + self.cv.create_line((frist_x,frist_y),(frist_x+40,frist_y),(frist_x+45,frist_y-30),fill='#94D050',tags='line') + # 画出详情表 + self.detail_true = self.cv.create_rectangle(frist_x+30,frist_y-120,frist_x+180,frist_y-30,outline='#94D050',tags='line') + # 画出相应的绿条数据 + self.cv.create_text(frist_x+50,frist_y-110,text='应用层',tags='line') + self.cv.create_text(frist_x+50,frist_y-87,text='传输层',tags='line') + self.cv.create_text(frist_x+50,frist_y-64,text='IP 层',tags='line') + self.cv.create_text(frist_x+50,frist_y-42,text='链路层',tags='line') + # 画出 右侧绿色和蓝色的类进度条 + # 应用层 + self.cv.create_rectangle(frist_x+177,frist_y-115,frist_x+150,frist_y-100,fill='#94D050',outline='#94D050',tags='line') + self.cv.create_rectangle(frist_x+148,frist_y-115,frist_x+128,frist_y-100,fill='#00B0F0',outline='#00B0F0',tags='line') + # 传输层 + self.cv.create_rectangle(frist_x + 177, frist_y - 95, frist_x + 140, frist_y - 80, fill='#94D050', + outline='#94D050', tags='line') + self.cv.create_rectangle(frist_x + 138, frist_y - 95, frist_x + 113, frist_y - 80, fill='#00B0F0', + outline='#00B0F0', tags='line') + # IP 层 + self.cv.create_rectangle(frist_x + 177, frist_y - 73, frist_x + 130, frist_y - 58, fill='#94D050', + outline='#94D050', tags='line') + self.cv.create_rectangle(frist_x + 128, frist_y - 73, frist_x + 98, frist_y - 58, fill='#00B0F0', + outline='#00B0F0', tags='line') + # 传输层 + self.cv.create_rectangle(frist_x + 177, frist_y - 50, frist_x + 113, frist_y - 35, fill='#94D050', + outline='#94D050', tags='line') + self.cv.create_rectangle(frist_x + 111, frist_y - 50, frist_x + 78, frist_y - 35, fill='#00B0F0', + outline='#00B0F0', tags='line') + elif self.item[2] == 2: # 当type对象为2 画出路由器详情图 + # print(2) + frist_x = self.item[0] # 获取frist_x + frist_y = self.item[1] # 获取frist_y + # 这里缺少一个删除其他详情的步骤 + # 画出连接详情表的线 + self.cv.delete('line') + self.cv.create_line((frist_x, frist_y), (frist_x + 40, frist_y), (frist_x + 45, frist_y - 30), + fill='#94D050', tags='line') + # 画出详情表 如果需要全覆盖则需要添加一个fill + self.detail_true = self.cv.create_rectangle(frist_x + 30, frist_y - 120, frist_x + 180, frist_y - 30, + outline='#94D050', tags='line') + # 画出相应的绿条数据 + self.cv.create_text(frist_x + 50, frist_y - 110, text='应用层', tags='line') + self.cv.create_text(frist_x + 50, frist_y - 87, text='传输层', tags='line') + self.cv.create_text(frist_x + 50, frist_y - 64, text='IP 层', tags='line') + self.cv.create_text(frist_x + 50, frist_y - 42, text='链路层', tags='line') + # 画出 右侧绿色和蓝色的类进度条 + # 应用层 + self.cv.create_rectangle(frist_x + 177, frist_y - 115, frist_x + 150, frist_y - 100, fill='#D3D3D3', + outline='#D3D3D3', tags='line') + self.cv.create_rectangle(frist_x + 148, frist_y - 115, frist_x + 128, frist_y - 100, fill='#D3D3D3', + outline='#D3D3D3', tags='line') + # 传输层 + self.cv.create_rectangle(frist_x + 177, frist_y - 95, frist_x + 140, frist_y - 80, fill='#D3D3D3', + outline='#D3D3D3', tags='line') + self.cv.create_rectangle(frist_x + 138, frist_y - 95, frist_x + 113, frist_y - 80, fill='#D3D3D3', + outline='#D3D3D3', tags='line') + # IP 层 + self.cv.create_rectangle(frist_x + 177, frist_y - 73, frist_x + 130, frist_y - 58, fill='#94D050', + outline='#94D050', tags='line') + self.cv.create_rectangle(frist_x + 128, frist_y - 73, frist_x + 98, frist_y - 58, fill='#00B0F0', + outline='#00B0F0', tags='line') + # 传输层 + self.cv.create_rectangle(frist_x + 177, frist_y - 50, frist_x + 113, frist_y - 35, fill='#94D050', + outline='#94D050', tags='line') + self.cv.create_rectangle(frist_x + 111, frist_y - 50, frist_x + 78, frist_y - 35, fill='#00B0F0', + outline='#00B0F0', tags='line') + return None + + + + +if __name__ == '__main__': + pass \ No newline at end of file diff --git a/Internet/data_dispose_CR.py b/Internet/data_dispose_CR.py new file mode 100644 index 0000000..58541fc --- /dev/null +++ b/Internet/data_dispose_CR.py @@ -0,0 +1,70 @@ +# 导入函数 +from data_crud_sqlite import * + + +'''创建类来处理函数''' +class Show_Right_All(): + def __init__(self,cv,all_data): + self.cv = cv + self.all_data = all_data + + + # 创建函数 来处理获取的数据 + def Show_img(self,img_host,img_router): + self.loca_all = [] # 定义一个数组用来存数据 + # 将获取的所有数据处理 + for item in self.all_data: + ObjX = item['ObjX'] + ObjY = item['ObjY'] + ObjID = item['ObjID'] + loca = (ObjX, ObjY) + self.loca_all.append(loca) + # 显示图片 + if item['ObjType'] == 1: + self.cv.create_image(ObjX, ObjY, image=img_host, tags=ObjID) + # elif item['ObjType'] == 2: + else: + self.cv.create_image(ObjX, ObjY, image=img_router, tags=ObjID) + # 显示ObjLable + if item['ObjLable'] == 'A': + self.cv.create_text(ObjX, ObjY+27, text=item['ObjLable'], font=('蔚然雅黑',16,'bold'),fill='#C00000', tags=item['ObjLable']) + self.cv.create_text(ObjX, ObjY-32, text=item['IPAddr'], font=('蔚然雅黑',10,'bold'),fill='#C00000', tags=item['IPAddr']) + elif item['ObjLable'] == 'R1': + self.cv.create_text(ObjX+15, ObjY+25, text=item['ObjLable'], font=('蔚然雅黑',16,'bold'),fill='#C00000', tags=item['ObjLable']) + self.cv.create_text(ObjX-67, ObjY, text=item['IPAddr'], font=('蔚然雅黑', 10, 'bold'), fill='#C00000', + tags=item['IPAddr']) + # 通过联表查询获取IP地址 + ip_data_R1 = select_and_ip(2) + # print(ip_data_R1) + self.cv.create_text(ObjX+30, ObjY-30, text= ip_data_R1, font=('蔚然雅黑',10,'bold'),fill='#C00000', tags=ip_data_R1) + elif item['ObjLable'] == 'R2': + self.cv.create_text(ObjX-17, ObjY+25, text=item['ObjLable'], font=('蔚然雅黑',16,'bold'),fill='#C00000', tags=item['ObjLable']) + self.cv.create_text(ObjX, ObjY - 32, text=item['IPAddr'], font=('蔚然雅黑', 10, 'bold'), fill='#C00000', + tags=item['IPAddr']) + elif item['ObjLable'] == 'R4': + self.cv.create_text(ObjX-35, ObjY, text=item['ObjLable'], font=('蔚然雅黑',16,'bold'),fill='#C00000', tags=item['ObjLable']) + self.cv.create_text(ObjX+20, ObjY - 29, text=item['IPAddr'], font=('蔚然雅黑', 10, 'bold'), fill='#C00000', + tags=item['IPAddr']) + ip_data_R4 = select_and_ip(4) + self.cv.create_text(ObjX - 10, ObjY + 26, text=ip_data_R4, font=('蔚然雅黑', 10, 'bold'), fill='#C00000', + tags=ip_data_R4) + elif item['ObjLable'] == 'R5': + self.cv.create_text(ObjX, ObjY+27, text=item['ObjLable'], font=('蔚然雅黑',16,'bold'),fill='#C00000', tags=item['ObjLable']) + self.cv.create_text(ObjX-67, ObjY - 12, text=item['IPAddr'], font=('蔚然雅黑', 10, 'bold'), fill='#C00000', + tags=item['IPAddr']) + ip_data_R5 = select_and_ip(5) + self.cv.create_text(ObjX - 67, ObjY + 3, text=ip_data_R5, font=('蔚然雅黑', 10, 'bold'), fill='#C00000', + tags=ip_data_R5) + elif item['ObjLable'] == 'D': + self.cv.create_text(ObjX-31, ObjY+10, text=item['ObjLable'], font=('蔚然雅黑',16,'bold'),fill='#C00000', tags=item['ObjLable']) + self.cv.create_text(ObjX, ObjY + 27, text=item['IPAddr'], font=('蔚然雅黑', 10, 'bold'), fill='#C00000', + tags=item['IPAddr']) + elif item['ObjLable'] == 'C': + self.cv.create_text(ObjX+25, ObjY-27, text=item['ObjLable'], font=('蔚然雅黑',16,'bold'),fill='#C00000', tags=item['ObjLable']) + self.cv.create_text(ObjX, ObjY + 27, text=item['IPAddr'], font=('蔚然雅黑', 10, 'bold'), fill='#C00000', + tags=item['IPAddr']) + elif item['ObjLable'] == 'R3': + self.cv.create_text(ObjX, ObjY-30, text=item['ObjLable'], font=('蔚然雅黑',16,'bold'),fill='#C00000', tags=item['ObjLable']) + elif item['ObjLable'] == 'B': + self.cv.create_text(ObjX+30, ObjY+10, text=item['ObjLable'], font=('蔚然雅黑',16,'bold'),fill='#C00000', tags=item['ObjLable']) + return None \ No newline at end of file diff --git a/Internet/data_envelop.py b/Internet/data_envelop.py new file mode 100644 index 0000000..b0bdde6 --- /dev/null +++ b/Internet/data_envelop.py @@ -0,0 +1,456 @@ +# 在这里实现移动信封并实现,并在实现的同时使最下方和最右方的canvas中显示数据 +import copy +import tkinter as tk +import time +from data_detail import Detail_Show, Show_green_detail +from data_crud_sqlite import * +# 建立全局变量 +num_begin_x = 0 +num_begin_y = 0 +num_end_x = 1 +num_end_y = 1 + +# 建立信封移动并处理输出数据的函数 +class EnvelopMove(): + def __init__(self,cv,img_host,img_router,img_envelop,img_detail,move_data,Objshow_data,AppPackTag_Data, + unpacket,move_number,right_on_text,right_under_text,under_text): + self.cv = cv # 主页面最大的canvas页面 + self.unpacket = unpacket # 这是一个函数,暂时没用 + self.img_host = img_host # 主机png图片 + self.img_router = img_router # png图片 + self.img_detail = img_detail # png图片 + self.img_envelop = img_envelop # 信封的png图片 + self.move_data = move_data # 信封的移动位置的数据集合 数据样式:[(229, 202, 'SH01', 1), (300, 300, 'SR01', 2)] + self.x1 = self.move_data[0][0] # 定义初始信封的x轴位置 + self.y1 = self.move_data[0][1] # 定义初始信封的y轴位置 + self.Begin_x = None # 定义一个用来存储移动数据的x轴值 + self.End_y = None # 定义一个用来存储移动数据的y轴值 + self.num_begin_x = 0 # 定义获取数组的第一个对比值 + self.num_begin_x_2 = 0 + self.num_begin_x_3 = 0 # 第三次 + self.num_end_x = 1 # 定义获取数组的下一个对比值 + self.num_end_x_2 = 1 + self.num_end_x_3 = 1 # 第三次 + self.num_begin_y = 0 # 定义获取数据下的固定位置值0 + self.num_end_y = 1 # 定义获取数据下的固定位置值1 + self.coord_Ture = True # 定义一个判断用来使用croods函数 + self.move_number_frist = 1 # 定义一个移动数据的初始值 + self.move_number_last = move_number # 数据为需要循环移动信封的次数 该数据为最后值 + self.move_number_add = False # 定义一个值用来实现信封循环发送的判断值 + self.move_number_add_2 = False # 第二次循环进入第三次 + self.right_on_text = right_on_text # 发送主机文本框 + self.right_under_text = right_under_text # 接收主机文本框 + self.under_text = under_text # 连续信息数据文本框 + self.Objshow_data = Objshow_data # 发送的数据总体信息 + self.AppPackTag_Data = AppPackTag_Data # 输入数据总体 + self.number_late = 0 # 设置循环输出的例子 + self.number_late_1 = 0 + self.number_late_2 = 0 + self.one_print_1 = True # 判断是否为第一次输出 + self.one_print_2 = True # 第二次 + self.one_print_3 = True + self.last_envelop_number = int(self.AppPackTag_Data['AppPackSize']) % 2048 + + + # 创建一个信封对象 + def main_envelop(self): + '''在这个位置编写发送和接收文本框中的信息''' + data_Send_0 = '发送主机: '+self.Objshow_data[0]['ObjLable']+'\n' + data_Send_1 = 'IP地址: '+self.Objshow_data[0]['IPAddr']+'\n' # 发送主机详情第一行 + data_Send_2 = 'Mac地址: '+self.Objshow_data[0]['MACAddr']+'\n' # 发送主机详情第二行 + data_Send_3 = '发送数据包大小: '+self.AppPackTag_Data['AppPackSize']+'KB'+'\n' # 发送主机详情第三行 + data_Send_4 = '已发送数据包数量: 0'+'\n' # 发送主机详情第四行 + data_Send_5 = '需要发送的数据包总数: '+str(self.move_number_last)+'\n' + self.right_on_text.insert(tk.END, data_Send_0) + self.right_on_text.insert(tk.END, data_Send_1) + self.right_on_text.insert(tk.END, data_Send_2) + self.right_on_text.insert(tk.END, data_Send_3) + self.right_on_text.insert(tk.END, data_Send_4) + self.right_on_text.insert(tk.END, data_Send_5) + data_Req_1 = '接收主机: '+self.Objshow_data[-1]['ObjLable']+'\n' + data_Req_2 = 'IP地址: '+self.Objshow_data[-1]['IPAddr']+'\n' + data_Req_3 = 'Mac地址: '+self.Objshow_data[-1]['MACAddr']+'\n' + data_Req_4 = '接收数据包大小: '+self.AppPackTag_Data['AppPackSize']+'KB'+'\n' + data_Req_5 = '已接收的数据包数量: 0'+'\n' + data_Req_6 = '需要接收的数据包总数: '+str(self.move_number_last)+'\n' + self.right_under_text.insert(tk.END, data_Req_1) + self.right_under_text.insert(tk.END, data_Req_2) + self.right_under_text.insert(tk.END, data_Req_3) + self.right_under_text.insert(tk.END, data_Req_4) + self.right_under_text.insert(tk.END, data_Req_5) + self.right_under_text.insert(tk.END, data_Req_6) + self.envelop_1 = self.cv.create_image(self.x1, self.y1, image=self.img_envelop,tags='envelop') # 在初始位置创建一个信封图标 + self.show_data_move() + if self.move_number_last >= 2: + self.envelop_2 = self.cv.create_image(self.x1, self.y1, image=self.img_envelop,tags='envelop') + if self.move_number_last >= 3: + self.envelop_3 = self.cv.create_image(self.x1, self.y1, image=self.img_envelop,tags='envelop') + return None + + + # 类似建立模拟函数,第一步先建立信封显示 + def show_data_move(self): + '''在这个位置添加一个判断用来设置新的envelop ?暂时存疑''' + if self.coord_Ture: + self.x_1, self.y_1 = self.cv.coords(self.envelop_1) + # print(self.x_1,self.y_1) + if self.one_print_1: + s_index = '5.10' + e_index = '5.11' + self.right_on_text.delete(s_index, e_index) + self.right_on_text.insert(e_index, '1') + data_one_1 = '发送主机:'+self.Objshow_data[0]['ObjLable']+'\n' # 第一次发送主机 + data_one_2 = '接收主机: '+self.Objshow_data[-1]['ObjLable']+'\n' # 第二行 + data_one_3 = '数据包大小: '+self.AppPackTag_Data['AppPackSize']+'KB'+'\n' # 第三行 + self.one_print_1 = False + if self.num_end_x <= (len(self.move_data)-1): + # self.Begin_x 为需要x轴移动的距离 + Begin_x = self.move_data[self.num_end_x][self.num_begin_y]-self.move_data[self.num_begin_x][self.num_begin_y] + # self.End_y 为需要y轴移动的距离 + End_y = self.move_data[self.num_end_x][self.num_end_y]-self.move_data[self.num_begin_x][self.num_end_y] + # 移动信封 + self.cv.move(self.envelop_1, Begin_x/100, End_y/100) + if int(self.move_data[self.num_end_x][self.num_begin_y]) - 2 <= self.x_1 <= int( + self.move_data[self.num_end_x][self.num_begin_y]) + 2 and int( + self.move_data[self.num_end_x][self.num_end_y]) - 2 <= self.y_1 <= int( + self.move_data[self.num_end_x][self.num_end_y]) + 2: + time.sleep(1) + self.num_begin_x = self.num_begin_x + 1 + self.num_end_x = self.num_end_x + 1 + self.move_number_add = True + data_late_1 = '发送对象: '+self.Objshow_data[self.number_late]['ObjLable']+'\n' + data_late_1_1 = '发送对象IP地址: '+self.Objshow_data[self.number_late]['IPAddr']+'\n' + data_late_1_2 = '发送对象Mac地址: '+self.Objshow_data[self.number_late]['MACAddr']+'\n' + data_late_1_3 = '数据包对象: '+'1'+' / '+str(self.move_number_last)+'\n' + if self.move_number_last == 1: + data_late_1_4 = '数据包大小: '+str(self.last_envelop_number)+' KB \n' + else: + data_late_1_4 = '数据包大小: '+'2048 KB \n' + data_late_1_5 = '数据解包中...... \n' + data_late_1_6 = '数据解包完成 \n' + data_late_2 = '接收对象:'+self.Objshow_data[self.number_late+1]['ObjLable']+'\n' + data_late_2_1 = '接收对象IP地址: '+self.Objshow_data[self.number_late+1]['IPAddr']+'\n' + data_late_2_2 = '接收对象Mac地址: '+self.Objshow_data[self.number_late+1]['MACAddr']+'\n' + data_late_2_3 = '数据封包中...... \n' + data_late_2_4 = '数据封包完成 \n' + self.under_text.insert(tk.END, '*' * 15 + '第一个数据包信息' + '*' * 15 + '\n') + self.under_text.insert(tk.END, data_late_1) + self.under_text.insert(tk.END, data_late_1_1) + self.under_text.insert(tk.END, data_late_1_2) + self.under_text.insert(tk.END, data_late_1_3) + self.under_text.insert(tk.END, data_late_1_4) + self.under_text.insert(tk.END, data_late_1_5) + self.under_text.insert(tk.END, data_late_1_6) + self.under_text.insert(tk.END, data_late_2) + self.under_text.insert(tk.END, data_late_2_1) + self.under_text.insert(tk.END, data_late_2_2) + self.under_text.insert(tk.END, data_late_2_3) + self.under_text.insert(tk.END, data_late_2_4) + self.number_late += 1 + self.cv.after(12, self.show_data_move) + if self.move_number_add and self.move_number_last >= 2: + self.show_data_move_2() + elif self.num_end_x == len(self.move_data): + self.start_index = "5.11" + self.end_index = "5.12" + self.right_under_text.delete(self.start_index, self.end_index) + self.right_under_text.insert(self.end_index, '1') + if self.move_number_last == 1: + self.cv.delete('envelop') + self.coord_Ture = False + self.detail_data = Detail_Show(cv=self.cv, img_detail=self.img_detail, move_data=self.move_data).show_detail() + return None + + # 建立移动第二个信封的函数 + def show_data_move_2(self): + if self.coord_Ture: + self.x_2, self.y_2 = self.cv.coords(self.envelop_2) + if self.one_print_2: + s_index = '5.10' + e_index = '5.11' + self.right_on_text.delete(s_index, e_index) + self.right_on_text.insert(e_index, '2') + self.one_print_2 = False + if self.num_end_x_2 <= (len(self.move_data) - 1): + # self.Begin_x 为需要x轴移动的距离 + Begin_x = self.move_data[self.num_end_x_2][self.num_begin_y] - self.move_data[self.num_begin_x_2][ + self.num_begin_y] + # self.End_y 为需要y轴移动的距离 + End_y = self.move_data[self.num_end_x_2][self.num_end_y] - self.move_data[self.num_begin_x_2][ + self.num_end_y] + # 移动信封 + self.cv.move(self.envelop_2, Begin_x / 100, End_y / 100) + if int(self.move_data[self.num_end_x_2][self.num_begin_y]) - 2 <= self.x_2 <= int( + self.move_data[self.num_end_x_2][self.num_begin_y]) + 2 and int( + self.move_data[self.num_end_x_2][self.num_end_y]) - 2 <= self.y_2 <= int( + self.move_data[self.num_end_x_2][self.num_end_y]) + 2: + # time.sleep(0.1) + self.num_begin_x_2 = self.num_begin_x_2 + 1 + self.num_end_x_2 = self.num_end_x_2 + 1 + self.move_number_add_2 = True # 当第二个信封进入到第二个节点时,将数据进入到第三个 + '''在这里添加一段输出数据试试判断试试''' + self.under_text.insert(tk.END, '#' * 15 + '第二个数据包信息' + '#' * 15 + '\n') + data_late_1 = '发送对象: ' + self.Objshow_data[self.number_late_1]['ObjLable'] + '\n' + data_late_1_1 = '发送对象IP地址: ' + self.Objshow_data[self.number_late_1]['IPAddr'] + '\n' + data_late_1_2 = '发送对象Mac地址: ' + self.Objshow_data[self.number_late_1]['MACAddr'] + '\n' + data_late_1_3 = '数据包对象: ' + '2' + ' / ' + str(self.move_number_last) + '\n' + if self.move_number_last == 2: + data_late_1_4 = '数据包大小: ' + str(self.last_envelop_number) + ' KB \n' + else: + data_late_1_4 = '数据包大小: ' + '2048 KB \n' + data_late_1_5 = '数据解包中...... \n' + data_late_1_6 = '数据解包完成 \n' + data_late_2 = '接收对象:' + self.Objshow_data[self.number_late_1 + 1]['ObjLable'] + '\n' + data_late_2_1 = '接收对象IP地址: ' + self.Objshow_data[self.number_late_1 + 1]['IPAddr'] + '\n' + data_late_2_2 = '接收对象Mac地址: ' + self.Objshow_data[self.number_late_1 + 1]['MACAddr'] + '\n' + data_late_2_3 = '数据封包中...... \n' + data_late_2_4 = '数据封包完成 \n' + self.under_text.insert(tk.END, data_late_1) + self.under_text.insert(tk.END, data_late_1_1) + self.under_text.insert(tk.END, data_late_1_2) + self.under_text.insert(tk.END, data_late_1_3) + self.under_text.insert(tk.END, data_late_1_4) + self.under_text.insert(tk.END, data_late_1_5) + self.under_text.insert(tk.END, data_late_1_6) + self.under_text.insert(tk.END, data_late_2) + self.under_text.insert(tk.END, data_late_2_1) + self.under_text.insert(tk.END, data_late_2_2) + self.under_text.insert(tk.END, data_late_2_3) + self.under_text.insert(tk.END, data_late_2_4) + self.number_late_1 += 1 + if self.num_end_x_2 == 5: + self.cv.after(12, self.show_data_move_2) + # time.sleep(1) + if self.move_number_add_2 and self.move_number_last>=3: + self.show_data_move_3() + elif self.num_end_x_2 == len(self.move_data): + self.right_under_text.delete(self.start_index, self.end_index) + self.right_under_text.insert(self.end_index, '2') + if self.move_number_last == 2: + self.cv.delete('envelop') + self.coord_Ture = False + self.detail_data = Detail_Show(cv=self.cv, img_detail=self.img_detail, move_data=self.move_data).show_detail() + return None + + # 建立移动第三个信封的函数 + def show_data_move_3(self): + if self.coord_Ture: + self.x_3, self.y_3 = self.cv.coords(self.envelop_3) + if self.one_print_3: + s_index = '5.10' + e_index = '5.11' + self.right_on_text.delete(s_index, e_index) + self.right_on_text.insert(e_index, '3') + self.one_print_3 = False + if self.num_end_x_3 <= (len(self.move_data) - 1): + # self.Begin_x 为需要x轴移动的距离 + Begin_x = self.move_data[self.num_end_x_3][self.num_begin_y] - self.move_data[self.num_begin_x_3][ + self.num_begin_y] + # self.End_y 为需要y轴移动的距离 + End_y = self.move_data[self.num_end_x_3][self.num_end_y] - self.move_data[self.num_begin_x_3][ + self.num_end_y] + # 移动信封 + self.cv.move(self.envelop_3, Begin_x / 100, End_y / 100) + if int(self.move_data[self.num_end_x_3][self.num_begin_y]) - 2 <= self.x_3 <= int( + self.move_data[self.num_end_x_3][self.num_begin_y]) + 2 and int( + self.move_data[self.num_end_x_3][self.num_end_y]) - 2 <= self.y_3 <= int( + self.move_data[self.num_end_x_3][self.num_end_y]) + 2: + # time.sleep(0.1) + self.num_begin_x_3 = self.num_begin_x_3 + 1 + self.num_end_x_3 = self.num_end_x_3 + 1 + + self.under_text.insert(tk.END, '*' * 15 + '第三个数据包信息' + '*' * 15 + '\n') + data_late_1 = '发送对象: ' + self.Objshow_data[self.number_late_2]['ObjLable'] + '\n' + data_late_1_1 = '发送对象IP地址: ' + self.Objshow_data[self.number_late_2]['IPAddr'] + '\n' + data_late_1_2 = '发送对象Mac地址: ' + self.Objshow_data[self.number_late_2]['MACAddr'] + '\n' + data_late_1_3 = '数据包对象: ' + '2' + ' / ' + str(self.move_number_last) + '\n' + if self.move_number_last ==3 : + data_late_1_4 = '数据包大小: ' + str(self.last_envelop_number) + ' KB \n' + else: + data_late_1_4 = '数据包大小: ' + '2048 KB \n' + data_late_1_5 = '数据解包中...... \n' + data_late_1_6 = '数据解包完成 \n' + data_late_2 = '接收对象:' + self.Objshow_data[self.number_late_2 + 1]['ObjLable'] + '\n' + data_late_2_1 = '接收对象IP地址: ' + self.Objshow_data[self.number_late_2 + 1]['IPAddr'] + '\n' + data_late_2_2 = '接收对象Mac地址: ' + self.Objshow_data[self.number_late_2 + 1]['MACAddr'] + '\n' + data_late_2_3 = '数据封包中...... \n' + data_late_2_4 = '数据封包完成 \n' + self.under_text.insert(tk.END, data_late_1) + self.under_text.insert(tk.END, data_late_1_1) + self.under_text.insert(tk.END, data_late_1_2) + self.under_text.insert(tk.END, data_late_1_3) + self.under_text.insert(tk.END, data_late_1_4) + self.under_text.insert(tk.END, data_late_1_5) + self.under_text.insert(tk.END, data_late_1_6) + self.under_text.insert(tk.END, data_late_2) + self.under_text.insert(tk.END, data_late_2_1) + self.under_text.insert(tk.END, data_late_2_2) + self.under_text.insert(tk.END, data_late_2_3) + self.under_text.insert(tk.END, data_late_2_4) + self.number_late_2 += 1 + if self.num_end_x_3 == 5: + # time.sleep(1) + self.cv.after(12, self.show_data_move_3) + + elif self.num_end_x_3 == len(self.move_data): + self.right_under_text.delete(self.start_index, self.end_index) + self.right_under_text.insert(self.end_index, '3') + if self.move_number_last == 3: + self.cv.delete('envelop') + self.coord_Ture = False + self.detail_data = Detail_Show(cv=self.cv, img_detail=self.img_detail, move_data=self.move_data).show_detail() + return None + + # 在这里创建鼠标左键点击详情头位置显示数据 + def show_detail_all(self, event): + frist_X = event.x + frist_y = event.y + for item in self.detail_data: + if frist_X-10", self.show_detail_all) # 点击鼠标左键触发显示数据函数 + return Mouse + + +# 创建修改objshow列的函数 +def revise_objshow(send_host, reception_host): + '''在这个位置判断发送主机和接收主机的位置并修改其数据''' + if send_host == 'A': + if reception_host == 'B': + # 调用函数修改objshow列为 0 + reve_objshow() + # 建立一个经过对象的数组 + after_data = ['A', 'R1', 'B'] + # 调用函数reve_after来给对象重新赋值 + reve_after(after_data) + '''后面可能需要在建立一个重组对象数组的功能''' + elif reception_host == 'C': + reve_objshow() + after_data = ['A', 'R1', 'R2', 'R4', 'R5', 'C'] + reve_after(after_data) + elif reception_host == 'D': + reve_objshow() + after_data = ['A', 'R1', 'R2', 'R4', 'R5', 'D'] + reve_after(after_data) + elif send_host == 'B': + if reception_host == 'A': + reve_objshow() + after_data = ['B', 'R1', 'A'] + reve_after(after_data) + elif reception_host == 'C': + reve_objshow() + after_data = ['B', 'R1', 'R2', 'R4', 'R5', 'C'] + reve_after(after_data) + elif reception_host == 'D': + reve_objshow() + after_data = ['B', 'R1', 'R2', 'R4', 'R5', 'C'] + reve_after(after_data) + elif send_host == 'C': + if reception_host == 'A': + reve_objshow() + after_data = ['C', 'R5', 'R4', 'R2', 'R1', 'A'] + reve_after(after_data) + elif reception_host == 'B': + reve_objshow() + after_data = ['C', 'R5', 'R4', 'R2', 'R1', 'A'] + reve_after(after_data) + elif reception_host == 'D': + reve_objshow() + after_data = ['C', 'R5', 'D'] + reve_after(after_data) + elif send_host == 'D': + if reception_host == 'A': + reve_objshow() + after_data = ['D', 'R5', 'R4', 'R2', 'R1', 'A'] + reve_after(after_data) + elif reception_host == 'B': + reve_objshow() + after_data = ['D', 'R5', 'R4', 'R2', 'R1', 'B'] + reve_after(after_data) + elif reception_host == 'C': + reve_objshow() + after_data = ['D', 'R5', 'C'] + reve_after(after_data) + return after_data + + +# 将数组顺序倒换并返回倒序数组 +def order_array(array, send_host, reception_host): + if send_host == 'D': + if reception_host == 'A': + array = array[::-1] + elif reception_host == 'B': + ObjID_reception = select_ObjLable_ObjID(reception_host) + ObjID_send = select_ObjLable_ObjID(send_host) + array = array[::-1] + for item in array: + if item == ObjID_send: + index_move_send = array.index(ObjID_send) + array = [ObjID_send]+array[:index_move_send]+array[index_move_send+1:] + elif item == ObjID_reception: + index_move_reception = array.index(ObjID_reception) + array = array[:index_move_reception]+array[index_move_reception+1:]+[ObjID_reception] + else: + pass + elif reception_host == 'C': + ObjID_send = select_ObjLable_ObjID(send_host) + for item in array: + if item == ObjID_send: + index_move_send = array.index(ObjID_send) + array = [ObjID_send]+array[:index_move_send]+array[index_move_send+1:] + else: + pass + elif send_host == 'C': + if reception_host == 'A': + array = array[::-1] + elif reception_host == 'B': + ObjID_reception = select_ObjLable_ObjID(reception_host) + ObjID_send = select_ObjLable_ObjID(send_host) + array = array[::-1] + for item in array: + if item == ObjID_send: + index_move_send = array.index(ObjID_send) + array = [ObjID_send] + array[:index_move_send] + array[index_move_send + 1:] + elif item == ObjID_reception: + index_move_reception = array.index(ObjID_reception) + array = array[:index_move_reception] + array[index_move_reception + 1:] + [ObjID_reception] + else: + pass + elif reception_host == 'D': + ObjID_send = select_ObjLable_ObjID(send_host) + for item in array: + if item == ObjID_send: + index_move_send = array.index(ObjID_send) + array = [ObjID_send] + array[:index_move_send] + array[index_move_send + 1:] + else: + pass + elif send_host == 'B': + if reception_host == 'A': + array = array[::-1] + elif reception_host == 'C' or reception_host == 'D': + ObjID_send = select_ObjLable_ObjID(send_host) + for item in array: + if item == ObjID_send: + index_move_send = array.index(ObjID_send) + array = [ObjID_send] + array[:index_move_send] + array[index_move_send + 1:] + else: + pass + return array + + + +'''建立一个函数使获取信封循环次数并为每次添加编号''' +def add_number(number): + number_all = [] + for i in range(0,number): + number = 'envelop_'+str(i+1) + number_all.append(number) + return number_all + + diff --git a/Internet/data_line.py b/Internet/data_line.py new file mode 100644 index 0000000..621f5b3 --- /dev/null +++ b/Internet/data_line.py @@ -0,0 +1,76 @@ + + +# 创建一个画线的类 +class Line_Right(): + def __init__(self, cv, line_data): + self.cv = cv + self.line_data = line_data + + # 创建函数来画出需要的线 + def line_test(self): + # 将数据通过循环取出,使用下标的形式 + for i in range(0, len(self.line_data)): + '''需要进行判断下标i+1存在数据''' + if i + 1 != len(self.line_data): + x = self.line_data[i]['ObjX'] + y = self.line_data[i]['ObjY'] + next_x = self.line_data[i + 1]['ObjX'] + next_y = self.line_data[i + 1]['ObjY'] + self.cv.create_line(x, y, next_x, next_y, width=3, fill='#5B9BD5') + # print(i) + return None + + +# 创建一个用于画出永久固定的无用的线的类 +class Useless_line(): + def __init__(self, cv, Useless_line_data): + self.cv = cv + self.Useless_line_data = Useless_line_data + + + # 创建函数用来画出线 + def draw_line_less(self): + data_all_zero = self.data_handle() + # 通过循环判断获取的对象是谁,在给该对象画出线条 + for item in data_all_zero: + # 在这里添加判断 + if item['ID'] == 7: # 这个以后换一个判断信息 + # 在这里画出线 + self.cv.create_line(item['ObjX'],item['ObjY'],250,160,width=3, fill='#00B050') + if item['ID'] == 8: + # 在这里画出连接三条线 + self.cv.create_line(item['ObjX'],item['ObjY'],370,130,width=1, fill='#5B9BD5') + self.cv.create_line(item['ObjX'], item['ObjY'], 400, 200, width=1, fill='#5B9BD5') + self.cv.create_line(item['ObjX'], item['ObjY'], 480, 260, width=1, fill='#5B9BD5') + if item['ID'] == 9: + self.cv.create_line(item['ObjX'], item['ObjY'], 480, 260, width=2, fill='#5B9BD5') + return None + + # 建立函数用来处理获取的数据 + def data_handle(self): + data_ObjShow_zero_all = [] + for item in self.Useless_line_data: + # print(item) + if item['ObjShow'] == 0: + # print(item) + data_ObjShow_zero_all.append(item) + # print(data_ObjShow_zero_all) + return data_ObjShow_zero_all + + + +# 对获取的line_data进行处理 +def line_draw(ShowData): + line_data_all = [] # 定义一个数组用来存储所有数据 + # 将获取的数据循环获取需要的数据 + for item in ShowData: + # print(item) + ObjX = item['ObjX'] + ObjY = item['ObjY'] + line_data = { + 'ObjX': ObjX, + 'ObjY': ObjY + } + line_data_all.append(line_data) + # print(line_data_all) + return line_data_all diff --git a/Internet/internet.db b/Internet/internet.db new file mode 100644 index 0000000..d1e1b74 Binary files /dev/null and b/Internet/internet.db differ diff --git a/Internet/judgement_data.py b/Internet/judgement_data.py new file mode 100644 index 0000000..8e915b1 --- /dev/null +++ b/Internet/judgement_data.py @@ -0,0 +1,157 @@ +# 建立一个函数用来判断封包数据的正确性 +''' +在这里编写数据包正误判断 +在这里引入数据 +test: 先使用自身对比判断出错误环节,or与下一层产生的数据对比是否出错。 +判断是否要写成一个函数呢?在数据处理函数中直接判断会不会好一点呢? +目前想法是先判断自己吧。 +自己进行判断的话则不需要额外写外接函数。 +TRUE == 对自身获取的地址进行判断正误、判断格式。 +''' +import re + +# 定义一个正则表达式来判断ip地址的格式是否正确 + +zz_ip = '^(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|[1-9])\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)\.(1\d{2}|2[0-4]\d|25[0-5]|[1-9]\d|\d)$' +zz_mac = '([0-9a-fA-F]{2}[:]){5}([0-9a-fA-F]{2})' +compile_ip = re.compile(zz_ip) +compile_mac = re.compile(zz_mac) + +# 判断是否符合ip地址格式要求 +def Judgement_Zz_IP(IP_Data): + if compile_ip.match(IP_Data): + return True + else: + return False + + +def Judgement_Zz_MAC(MAC_Data): + if compile_mac.match(MAC_Data): + return True + else: + return False + +# 判断AppData数据正误,地址是否存在,判断格式. +def Judgement_AppData(SourceAppAddr, TargetAppAddr): + ''' + 在这里添加判断数据正确性的代码 备注:test 目前 + 不知道需要对比的数据是啥所以先对比自身 + 不建议使用for循环,可以使用if嵌套 + ''' + # 将获取的数据进行切割 + SourceAppAddr = SourceAppAddr.split(':')[0] + TargetAppAddr = TargetAppAddr.split(':')[0] + # print(SourceAppAddr) + source = Judgement_Zz_IP(SourceAppAddr) # 发出数据IP判断 + if source != True: + print('SourceIP地址格式错误') + target = Judgement_Zz_IP(TargetAppAddr) # 接收数据IP判断 + if target != True: + print('TargetIP地址格式错误') + return None + +# 判断TransData数据正误 判断地址是否与上级地址是都一样。是否存在,外加判断端口号是否符合要求是否存在 +def Judgement_TransData(Old_SourceAppAddr,Old_TargetAppAddr,New_SourceAppAddr,New_TargetAppAddr,SentPort,RpctPort): + ''' + 在这里添加判断数据正确性的代码 备注:test 目前 + 不知道需要对比的数据是啥所以先对比自身 + 不建议使用for循环,可以使用if嵌套 + ''' + # 先判断地址是否符合格式在进行比较,先进行字符串的切割 + Old_SourceAppAddr = Old_SourceAppAddr.split(':')[0] + Old_TargetAppAddr = Old_TargetAppAddr.split(':')[0] + New_SourceAppAddr = New_SourceAppAddr.split(':')[0] + New_TargetAppAddr = New_TargetAppAddr.split(':')[0] + new_source = Judgement_Zz_IP(New_SourceAppAddr) + new_target = Judgement_Zz_IP(New_TargetAppAddr) + if new_source: + if Old_SourceAppAddr != New_SourceAppAddr: + print('新地址与原地址不相同') + else: + print('SourceIP地址格式错误') + if new_target: + if Old_TargetAppAddr != New_TargetAppAddr: + print('新地址与原地址不相同') + else: + print('TargetIP地址格式错误') + # 判断端口号是否符合要求 + if SentPort < 2048 or SentPort > 65535: + print('端口号不符合格式') + if RpctPort< 2048 or RpctPort > 65535: + print('端口号不符合格式') + return None + + + +# 判断IPData数据正误 +def Judgement_IPData(Old_SourceIP,Old_TargetIP,New_SourceIP,New_TargetIP): + ''' + 在这里添加判断数据正确性的代码 备注:test 目前 + 不知道需要对比的数据是啥所以先对比自身 + 不建议使用for循环,可以使用if嵌套 + ''' + new_sourceIP = Judgement_Zz_IP(New_SourceIP) + new_targetIP = Judgement_Zz_IP(New_TargetIP) + if new_sourceIP: + if Old_SourceIP != New_SourceIP: + print('新地址与原地址不相同') + else: + print('SourceIP地址格式错误') + if new_targetIP: + if Old_TargetIP != New_TargetIP: + print('新地址与原地址不相同') + else: + print('TargetIP地址格式错误') + return None + + + + +# 判断MACData数据正误 +def Judgement_MACData(Old_SourceIP,Old_TargetIP,New_SourceIP,New_TargetIP,SentMAC,RcptMAC): + ''' + 在这里添加判断数据正确性的代码 备注:test 目前 + 不知道需要对比的数据是啥所以先对比自身 + 不建议使用for循环,可以使用if嵌套 + ''' + new_sourceIP = Judgement_Zz_IP(New_SourceIP) + new_targetIP = Judgement_Zz_IP(New_TargetIP) + if new_sourceIP: + if Old_SourceIP != New_SourceIP: + print('新地址与原地址不相同') + else: + print('SourceIP地址格式错误') + if new_targetIP: + if Old_TargetIP != New_TargetIP: + print('新地址与原地址不相同') + else: + print('TargetIP地址格式错误') + sentmac = Judgement_Zz_MAC(SentMAC) + rcptmac = Judgement_Zz_MAC(RcptMAC) + if sentmac != True: + print('SentMAC地址格式错误') + if rcptmac != True: + print('RcptMAC地址格式错误') + return None + + + +if __name__ == '__main__': + # 在这里建立一组test数据用来比较 + # test: 测试 + # Judgement_AppData('SHO1','A','AppPack1',6144,'A-6144-Data','101.1.1.2:18010','201.21.1.2:18010',test_4) + # Judgement_TransData('ObjID','IDkey','TransPackID','TransSeq','TransTag','AppPackID','SentPort','RpctPort','SourceAppAddr','TargetAppAddr',TransPackedString) + # Judgement_IPData('ObjID','IDkey','IP_number','IPPackID','TransPackID','SourceIP','TargetIP','SourceAppAddr','TargetAppAddr',IPPackedString) + # Judgement_MACData('ObjID','IDkey','MAC_number','MacPackID','IPPackID','SentMAC','RcptMAC','SourceIP','TargetIP','SourceAppAddr','TargetAppAddr',MacPackedString) + ip_test = '127.0.0.1:18010' + ip_test2 = '196.168.2.1:18010' + ip_test_new = '196.168.1.1' + ip_test2_new = '196.168.3.1' + prot = 1395 + prot_1 = 65555 + test_mac = '00:1a:8c:10:ad:30' + test_mac1 = '10:00:00:90:fa:02:88:00' + # print(Judgement_Zz_IP(ip_test)) + # Judgement_AppData(ip_test,ip_test2) + # Judgement_TransData(Old_SourceAppAddr=ip_test,Old_TargetAppAddr=ip_test2,New_SourceAppAddr=ip_test_new,New_TargetAppAddr=ip_test2_new,SentPort=prot,RpctPort=prot_1) + Judgement_MACData(Old_SourceIP=ip_test_new,Old_TargetIP=ip_test2_new,New_SourceIP=ip_test2_new,New_TargetIP=ip_test_new,SentMAC=test_mac,RcptMAC=test_mac1) \ No newline at end of file diff --git a/Internet/main_X4.py b/Internet/main_X4.py new file mode 100644 index 0000000..d926f07 --- /dev/null +++ b/Internet/main_X4.py @@ -0,0 +1,381 @@ +# 导入模块 +import tkinter as tk +from tkinter import * +from tkinter import messagebox +from data_crud_sqlite import * +from data_line import Line_Right, line_draw, Useless_line +from data_dispose_CR import Show_Right_All +from data_envelop import EnvelopMove, revise_objshow, order_array + +# 图片常量 +# img_host = PhotoImage(file='../images/主机_2.png') +# img_router = PhotoImage(file='../images/路由器_2.png') +# img_envelop = PhotoImage(file='../images/信封_2.png') +# img_detail = PhotoImage(file='../images/详情头_2.png') + +# 创建父窗口函数 +class Main_Gui(): + def __init__(self, init_window_name): + self.init_window_name = init_window_name + + + # 创建窗口界面 + def Set_init_window(self): + init_window_name = self.init_window_name + '''头歌虚拟平台上的屏幕长宽大概为: 宽:1360;高:690''' + # root_width = init_window_name.winfo_screenwidth() # 获取window屏幕宽度 + root_width = 1360 + self.root_width = int(root_width / 4 * 3) # 设置父窗口界面宽度 + # print('父窗口界面宽度:'+str(self.root_width)) # 输出父窗口界面宽度 + # root_height = init_window_name.winfo_screenheight() # 获取window屏幕长度 + root_height = 690 + self.root_height = int(root_height / 4 * 3) # 设置父窗口界面长度 + # print('父窗口界面长度:'+str(self.root_height)) # 输出父窗口界面长度 + init_window_name.title('数据封包和解包模拟&X1-X4') # 标题 + # 将窗口固定在屏幕中央 + init_window_name.geometry(str(self.root_width)+'x'+str(self.root_height)+'+'+str(int((root_width-self.root_width)/2))+'+'+str(int((root_height-self.root_height)/2))) # 窗口大小 + '''创建搭载在父窗口上的菜单''' + main_menu = tk.Menu(init_window_name) + + filemenu = Menu(main_menu, tearoff=False) # 设置子菜单 + filemenu.add_command(label='启动模拟', command=self.similar_packet) #模拟函数未完成 + filemenu.add_command(label='启动X4模拟', command=self.similar_packet_X4) # 需要建立函数 + filemenu.add_command(label='查找', command=quit) # 寻址功能函数未完成 + filemenu.add_separator() # 画线 + filemenu.add_command(label='退出', command=quit) # 点击关闭页面 + main_menu.add_cascade(label='open', menu=filemenu) # 主界面 + + init_window_name.config(menu=main_menu) # 将菜单按钮挂载在画布上 + + + '''创建和父窗口同等大小的canvas画布''' + self.cv = tk.Canvas(init_window_name, + bg='#f0f0f0', + # bg='white', + width=self.root_width-250, + height=self.root_height-150) + self.cv.pack(side=tk.LEFT, anchor=tk.NW) + # self.cv.grid(row=0, column=0) + # self.cv.pack(anchor=tk.NW) + # 画出包含仿真对象图的方框图 + self.cv.create_rectangle(100, 40, self.root_width - 250, self.root_height - 150, width=3, + outline="#7f6000") # 这个位置可能需要修改 + # 创建固定在左侧的标识符图像 + self.cv.create_image(50, 80, image=img_host) # 固定在左侧的主机对象 + self.cv.create_text(50, 110, text='主机', font=('蔚然雅黑', 14, 'bold'), fill='black') + self.cv.create_image(50, 160, image=img_router) # 固定在该canvas画布上的对象 == 路由器 + self.cv.create_text(50, 190, text='路由器', font=('蔚然雅黑', 14, 'bold'), fill='black') + + '''创建窗口前先将数据表simhost的数据恢复原样''' + revise_objshow('A','D') + '''画出仿真移动对象的图''' + self.Show_Canvas_Right() # 未完成 + + '''这个位置开始右侧详情页面''' + self.right_show_all() # 正在测试 未完成 + + '''设置最下方显示控件''' + self.under_show_all() # 未完成 + + + def similar_packet_X4(self): + # 删除窗口中的所有数据 + self.right_on_text.delete('1.0', tk.END) + self.right_under_text.delete('1.0', tk.END) + self.under_text.delete('1.0', tk.END) + self.cv.delete('detail');self.cv.delete('line') + # self.cv.unbind("",self.Mouse) # 清楚鼠标点击事件,修改中还未完成 2023-7-25 + self.open_envelop = False # 好像忘记了这个的作用了 + self.packet_emu_X4 = tk.Toplevel() + self.packet_emu_X4.title('X4-启动模拟') + self.packet_emu_X4.geometry('300x200+800+200') + # 建立数据模拟数据的输入框字体 + label_emu_x4_1 = tk.Label(self.packet_emu_X4, text='发送主机:').grid(row=0, pady=5) + label_emu_x4_2 = tk.Label(self.packet_emu_X4, text='接收主机:').grid(row=1, pady=5) + label_emu_x4_3 = tk.Label(self.packet_emu_X4, text='数据内容:').grid(row=2, pady=5) + label_emu_x4_4 = tk.Label(self.packet_emu_X4, text='数据大小(kb):').grid(row=3, pady=5) + label_emu_x4_5 = tk.Label(self.packet_emu_X4, text='数据标签:').grid(row=4, pady=5) + # 建立输入框 + self.entry_emu_x4_1 = tk.Entry(self.packet_emu_X4) + self.entry_emu_x4_1.grid(row=0, column=1) + + self.entry_emu_x4_2 = tk.Entry(self.packet_emu_X4) + self.entry_emu_x4_2.grid(row=1, column=1) + + self.entry_emu_x4_3 = tk.Entry(self.packet_emu_X4) + self.entry_emu_x4_3.grid(row=2, column=1) + + self.entry_emu_x4_4 = tk.Entry(self.packet_emu_X4) + self.entry_emu_x4_4.grid(row=3, column=1) + + self.entry_emu_x4_5 = tk.Entry(self.packet_emu_X4) + self.entry_emu_x4_5.grid(row=4, column=1) + + button_emu_left_X4 = tk.Button(self.packet_emu_X4, text='开启模拟', command=self.openpack_btn_x4).grid(row=5) # 函数未完成 2023-7-25 + return None + + # 设置X4模拟点击按钮后的函数 + def openpack_btn_x4(self): + # 先获取点击按钮后输入框中的数据 + entry_emu_x4_data_1 = self.entry_emu_x4_1.get() + entry_emu_x4_data_2 = self.entry_emu_x4_2.get() + entry_emu_x4_data_3 = self.entry_emu_x4_3.get() + entry_emu_x4_data_4 = self.entry_emu_x4_4.get() + entry_emu_x4_data_5 = self.entry_emu_x4_5.get() + + select_objlable = Select_ObjShow() # 查询数据库索取所有数据 + if entry_emu_x4_data_1=='' or entry_emu_x4_data_2=='' or entry_emu_x4_data_3==''or entry_emu_x4_data_4=='' or entry_emu_x4_data_5=='': + self.packet_emu_X4.destroy() + messagebox.showinfo('Error', '数据不能为空') + '''这个地方还需要添加一些其他的判断条件,暂且搁置''' + else: + self.packet_emu_X4.destroy() # 关闭启动模拟窗口 + self.AppPackTag_Data_X4 = { + 'SendHost': entry_emu_x4_data_1, 'ReceHost': entry_emu_x4_data_2, 'AppPackID': entry_emu_x4_data_3, 'AppPackSize': entry_emu_x4_data_4, 'AppPackTag': entry_emu_x4_data_5 + } + # print(self.AppPackTag_Data_X4) + self.move_number_x4 = int(self.AppPackTag_Data_X4['AppPackSize']) / 2048 + if self.move_number_x4 > 0 and self.move_number_x4 < 1: + self.move_number_x4 = 1 + elif self.move_number_x4 % 1 != 0: + self.move_number_x4 = int(self.move_number_x4 + 1) + # print('需要拆分成的数据包数量:'+str(self.move_number_x4)) + '''这个位置添加一个函数,通过获取的发送主机和接收主机的地址来修改数据库中ObjShow列中的数据''' + self.revise_objshow = revise_objshow(send_host=self.AppPackTag_Data_X4['SendHost'], reception_host=self.AppPackTag_Data_X4['ReceHost']) + '''这个位置调用信封移动的函数试试 PS:如果对象是如D——>A的则需要修改对象''' + # 如果需要修改数据之类的 + self.envelop_move_x4() + return None + + def envelop_move_x4(self): + '''在移动信封的同时需要设置在最下方显示进度提示,在最右边显示完成进度''' + '''建立一个暂时的变量,可以替换''' + self.unpacket = 0 + self.location_all_x4 = [] # 定义用来存放对象的位置 + self.Select_ObjID = Select_ObjID(self.revise_objshow) + for item in self.Select_ObjID: + # print(item) + ObjX = item['ObjX'];ObjY = item['ObjY'];ObjID = item['ObjID'];ObjType = item['ObjType'] + location = (ObjX, ObjY, ObjID, ObjType) + self.location_all_x4.append(location) + '''这个位置需要添加一个判断来判断是否需要将数组倒序''' + self.location_all_x4 = order_array(self.location_all_x4,self.AppPackTag_Data_X4['SendHost'],self.AppPackTag_Data_X4['ReceHost']) + # print(self.location_all_x4) + # 实现信封移动,并在实现的同时使最下方和最右方的canvas中显示数据 + '''这个位置需要通过获取的对象来获取值''' + # self.ObjShow_1_data = Select_ObjShow() + self.show_envelop = EnvelopMove(cv=self.cv, img_host=img_host, img_router=img_router, img_envelop=img_envelop, + img_detail=img_detail, move_data=self.location_all_x4, unpacket=self.unpacket, + move_number=self.move_number_x4, right_on_text=self.right_on_text, + Objshow_data=self.Select_ObjID, AppPackTag_Data=self.AppPackTag_Data_X4, + right_under_text=self.right_under_text, under_text=self.under_text) + self.show_envelop.main_envelop() + self.Mouse = self.show_envelop.Mouse_Event() + # self.show_envelop.show_data_move() + # print(self.ObjShow_1_data) + # print(self.location_all) + return None + + + '''# 设置一个编写类封包函数''' + def similar_packet(self): + self.right_on_text.delete('1.0', tk.END) + self.right_under_text.delete('1.0', tk.END) + self.under_text.delete('1.0', tk.END) + self.cv.delete('detail');self.cv.delete('line') + # self.cv.unbind("", self.Mouse) + # 定义一个值用来处理信封移动事件的开启 + self.open_envelop = False + # 建立一个子窗口完成数据 + self.packet_emu = tk.Toplevel() + self.packet_emu.title('启动模拟') + self.packet_emu.geometry('300x140+800+200') + # 建立数据模拟数据的输入框字体 + label_emu_1 = tk.Label(self.packet_emu, text='数据内容:').grid(row=0, pady=5) + label_emu_2 = tk.Label(self.packet_emu, text='数据大小(kb):').grid(row=1, pady=5) + label_emu_3 = tk.Label(self.packet_emu, text='数据标签:').grid(row=2, pady=5) + # 建立输入框 + self.entry_emu_1 = tk.Entry(self.packet_emu) + self.entry_emu_1.grid(row=0, column=1) + self.entry_emu_2 = tk.Entry(self.packet_emu) + self.entry_emu_2.grid(row=1, column=1) + self.entry_emu_3 = tk.Entry(self.packet_emu) + self.entry_emu_3.grid(row=2, column=1) + + # 创建按钮来开始模拟 + button_emu_left = tk.Button(self.packet_emu, text='开启模拟', command=self.openpack_btn).grid(row=5) # 函数未完成 + return None + + + '''创建openpack_btn函数启动按钮''' + def openpack_btn(self): + # 在关闭窗口前获取其中的数据 + entry_emu_1_data = self.entry_emu_1.get() + entry_emu_2_data = self.entry_emu_2.get() + entry_emu_3_data = self.entry_emu_3.get() + '''外接函数来获取对象的数据''' + self.select_objlable = select_ObjLable() + # # 添加if判断 + if entry_emu_1_data == '' or entry_emu_2_data == '' or entry_emu_3_data == '': + self.packet_emu.destroy() + messagebox.showinfo('Error', '数据不能为空') + # elif entry_emu_4_data == '' or entry_emu_5_data == '': + # self.packet_emu.destroy() + # messagebox.showinfo('Error', '发送主机or接收主机不能为空') + # elif entry_emu_4_data == entry_emu_5_data and entry_emu_4_data != '': + # self.packet_emu.destroy() + # messagebox.showinfo('Error', '发送主机和接收主机不能相同') + # elif entry_emu_4_data not in self.select_objlable and entry_emu_5_data not in self.select_objlable: + # self.packet_emu.destroy() + # messagebox.showinfo('Error', '发送主机or接收主机不存在') + else: + self.packet_emu.destroy() # 关闭启动模拟窗口 + # 获取的模拟数据包信息 + self.AppPackTag_Data = { + 'AppPackID': entry_emu_1_data, + 'AppPackSize': entry_emu_2_data, + 'AppPackTag': entry_emu_3_data + } + # print(self.AppPackTag_Data) + '''这里获取需要循环发送信封的次数''' + self.move_number = int(self.AppPackTag_Data['AppPackSize']) / 2048 + if self.move_number > 0 and self.move_number < 1: + self.move_number = 1 + elif self.move_number % 1 != 0: + self.move_number = int(self.move_number + 1) + # print('需要拆分成的数据包数量:'+str(self.move_number)) + # print(self.host_date) + # '''首先先建立一个判断两个主机之间是否存在通信的可能''' + # 建立一个数组用来存储需要循环显示的数据 + # 需要在这个位置创建一个tcp类似的子窗口 + # self.Mock_TCP() + '''这里建立外接函数,在移动信封的同时需要设置在最下方显示进度提示,在最右边显示完成进度''' + self.envelop_move() + return None + + '''编写模拟信封传送至交换机''' + def envelop_move(self): # 移动信封的函数主体 + '''在移动信封的同时需要设置在最下方显示进度提示,在最右边显示完成进度''' + '''建立一个暂时的变量,可以替换''' + self.unpacket = 0 + self.location_all = [] # 定义用来存放对象的位置 + for item in self.ObjShow_1_data: + # print(item) + ObjX = item['ObjX'];ObjY = item['ObjY'];ObjID = item['ObjID'];ObjType = item['ObjType'] + location = (ObjX, ObjY, ObjID, ObjType) + self.location_all.append(location) + # print(self.location_all) + # 实现信封移动,并在实现的同时使最下方和最右方的canvas中显示数据 + self.show_envelop = EnvelopMove(cv=self.cv,img_host=img_host, img_router=img_router, img_envelop=img_envelop,img_detail=img_detail,move_data=self.location_all,unpacket=self.unpacket, + move_number=self.move_number,right_on_text=self.right_on_text,Objshow_data=self.ObjShow_1_data,AppPackTag_Data=self.AppPackTag_Data, + right_under_text=self.right_under_text,under_text=self.under_text) + self.show_envelop.main_envelop() + self.Mouse = self.show_envelop.Mouse_Event() + # self.show_envelop.show_data_move() + # print(self.ObjShow_1_data) + # print(self.location_all) + return None + + # 设置画出对象详情数据的图 + def Show_Canvas_Right(self): + self.simhost_all_data = get_simhost_alldata() # 获取simhost表中的所有数据 + # print(self.simhost_all_data) + self.ObjShow_1_data = Select_ObjShow() # 采集所有ObjShow为1的数据 + # print(self.ObjShow_1_data) + self.line_data = line_draw(self.ObjShow_1_data) + # print(self.line_data) + '''外接画线函数''' + self.show_line = Line_Right(cv=self.cv, line_data=self.line_data) + self.show_line.line_test() + '''这个位置需要添加一个固定的line存在,用来连接并不需要连通线的对象.''' + self.useless_line = Useless_line(cv=self.cv, Useless_line_data=self.simhost_all_data) + # 显示不需要连接的线 + self.useless_line.draw_line_less() + '''调用函数将对象显示在方框内''' + self.show_cr = Show_Right_All(cv=self.cv, all_data=self.simhost_all_data) + self.show_cr.Show_img(img_host=img_host, img_router=img_router) + return None + # 测试 在最左侧实现详情数据 + def right_show_all(self): + '''更换编写方式使用最原本的text特性''' + self.right_on_label = tk.Label(self.init_window_name, text='发送主机详情:',font=('蔚然雅黑', 12, 'bold')) + # self.right_on_label.pack(side=tk.TOP, fill=tk.Y, padx=10, pady=10) + self.right_on_label.pack(anchor=tk.NW, fill=tk.Y, padx=5, pady=5) + # self.right_on_text = tk.Text(self.init_window_name, width=29, height=13) + self.right_on_text = tk.Text(self.init_window_name, width=24, height=10) + self.right_on_text.pack(anchor=tk.NW, fill=tk.Y, padx=5, pady=5) + self.right_under_label = tk.Label(self.init_window_name, text='接收主机详情:', font=('蔚然雅黑', 12, 'bold')) + self.right_under_label.pack(anchor=tk.NW, fill=tk.Y, padx=5, pady=5) + # self.right_under_text = tk.Text(self.init_window_name, width=29, height=13) + self.right_under_text = tk.Text(self.init_window_name, width=24, height=10) + self.right_under_text.pack(anchor=tk.NW, fill=tk.Y, padx=5, pady=5) + self.right_on_text.configure(font=("TkDefaultFont", 12)) + self.right_under_text.configure(font=("TkDefaultFont", 12)) + # self.canvas_right_detail = tk.Canvas(self.cv, width=290, height=700, bg='white') + # self.cv.create_window(1290, 280, window=self.canvas_right_detail, width=290, height=705) + # self.canvas_right_detail.create_text(80, 90, text='发送主机 '+self.ObjShow_1_data[0]['ObjLable']+' 详情:', font=('蔚然雅黑', 12, 'bold'), fill='black') + # '''在该canvas画布下的子画布中创建两个frame组件''' + # self.right_on_frame = tk.Frame(self.canvas_right_detail, width=280, height=270, bg='lightgray') + # self.canvas_right_detail.create_window(145, 250, window=self.right_on_frame) + # # 接收主机的属性 + # self.canvas_right_detail.create_text(80, 400, text='接收主机 '+self.ObjShow_1_data[-1]['ObjLable']+' 详情:', font=('蔚然雅黑', 12, 'bold'), fill='black') + # self.right_under_frame = tk.Frame(self.canvas_right_detail, width=280, height=270, bg='lightgray') + # self.canvas_right_detail.create_window(145, 560, window=self.right_under_frame) + # ''' + # 接下来的目的: + # 1.在下面的两个frame组件中加入文本框组件 + # 2.可以实现分批次的显示数据 + # ''' + # self.canvas_on_ftext = tk.Text(self.right_on_frame, width=10, height=10) + # self.canvas_on_ftext.pack() + return None + + # 测试 在最下方设置操作输出框 + def under_show_all(self): + '''更换方式显示''' + scrollbar_y = tk.Scrollbar(self.init_window_name) + scrollbar_y.place(x=760, y=380,relheight=0.25) + # scrollbar_x = tk.Scrollbar(self.init_window_name, orient=tk.HORIZONTAL) + # scrollbar_x.pack(side=tk.BOTTOM, fill=tk.X) + self.under_label = tk.Label(self.init_window_name, text='数据传输: ', font=('蔚然雅黑', 12, 'bold')) + # self.under_label.pack(side=tk.BOTTOM, anchor=tk.SW) + self.under_label.place(x=10, y=375) + # self.under_text = tk.Text(self.init_window_name, width=82, height=8) + self.under_text = tk.Text(self.init_window_name, width=65, height=8) + # self.under_text.place(x=140, y=638, relheight=1) + self.under_text.place(x=100, y=375) + self.under_text.configure(font=("TkDefaultFont", 12)) + scrollbar_y.config(command=self.under_text.yview) + self.under_text.config(yscrollcommand=scrollbar_y.set) + # scrollbar_x.config(command=self.under_text.xview) + # # 设置子canvas画布 + # self.canvas_under_detail = tk.Canvas(self.cv,width=2000, height=177, bg='white') + # self.cv.create_window(450, 720, window=self.canvas_under_detail, width=2000, height=177) + # self.canvas_under_detail.create_text(750, 21,text='数据传输进度: ', font=('蔚然雅黑', 12, 'bold'), fill='black') + # '''创建在最下方的canvas画布中的详情显示frame''' + # self.canvas_under_frame = tk.Frame(self.canvas_under_detail, width=1500, height=143, bg='lightgray') + # self.canvas_under_detail.create_window(1250, 105, window=self.canvas_under_frame) + return None + + + + + +if __name__ == '__main__': + init_Windows = tk.Tk() # 创建一个父窗口 + create_simhost() + create_ipaddr() + insert_simhost() + insert_ipaddr() + img_host = PhotoImage(file='/data/workspace/myshixun/images/主机_2.png') + img_router = PhotoImage(file='/data/workspace/myshixun/images/路由器_2.png') + img_envelop = PhotoImage(file='/data/workspace/myshixun/images/信封_2.png') + img_detail = PhotoImage(file='/data/workspace/myshixun/images/详情头_2.png') + # img_host = PhotoImage(file='../images/主机_2.png') + # img_router = PhotoImage(file='../images/路由器_2.png') + # img_envelop = PhotoImage(file='../images/信封_2.png') + # img_detail = PhotoImage(file='../images/详情头_2.png') + Gui = Main_Gui(init_Windows) + Gui.Set_init_window() + print('程序运行成功!') + init_Windows.mainloop() diff --git a/Internet/pack_un_all.py b/Internet/pack_un_all.py new file mode 100644 index 0000000..a7b84e8 --- /dev/null +++ b/Internet/pack_un_all.py @@ -0,0 +1,189 @@ +# 这个函数用来实现模拟解包过程 + + +# 创建类用来处理解包函数 +class Unpack_All(): + # 获取需要的数据 + def __init__(self,MacPacketString, IPPacketString, TransPacketString, AppPacketString): + self.MacPacketString = MacPacketString + self.IPPacketString = IPPacketString + self.TransPacketString = TransPacketString + self.AppPacketString = AppPacketString + + # 建立函数用来处理MacPacketString中的数据 + def unpack_mac_data(self): + # print(self.MacPacketString) + MacData_All = [] + # 将获取的数据分解成macdata中 + for item in self.MacPacketString: + ObjID = item['ObjID'] + ObjLable = item['ObjLable'] + MacPackId = item['MacPackId'] + IPPackID = item['IPPackID'] + sentmac = item['sentmac'] + rcptmac = item['rcptmac'] + sourceip = item['sourceip'] + targetip = item['targetip'] + sourceAppAddr = item['sourceAppAddr'] + targetAppAddr = item['targetAppAddr'] + MacData = { + 'ObjID': ObjID, + 'ObjLable': ObjLable, + 'MacPackId': MacPackId, + 'IPPackID': IPPackID, + 'sentmac': sentmac, + 'rcptmac': rcptmac, + 'sourceip': sourceip, + 'targetip': targetip, + 'sourceAppAddr': sourceAppAddr, + 'targetAppAddr': targetAppAddr, + 'MacPacketString': item + } + MacData_All.append(MacData) + return MacData_All + + # 建立函数用来处理IPPacket中的数据 + def unpack_ip_data(self): + IPData_All = [] + for item in self.IPPacketString: + ObjID = item['ObjID'] + ObjLable = item['ObjLable'] + IPPackID = item['IPPackID'] + TransPackID = item['TransPackID'] + sourceip = item['sourceip'] + targetip = item['targetip'] + sourceAppAddr = item['sourceAppAddr'] + targetAppAddr = item['targetAppAddr'] + IPData = { + 'ObjID': ObjID, + 'ObjLable': ObjLable, + 'IPPackID': IPPackID, + 'TransPackID': TransPackID, + 'sourceip': sourceip, + 'targetip': targetip, + 'sourceAppAddr': sourceAppAddr, + 'targetAppAddr': targetAppAddr, + 'IPPacketString': item + } + IPData_All.append(IPData) + return IPData_All + + + # 建立一个函数用来处理Trans的解包 + def unpack_trans_data(self): + TransData_All = [] + for item in self.TransPacketString: + ObjID = item['ObjID'] + ObjLable = item['ObjLable'] + TransPackID = item['TransPackID'] + TransSeq = item['TransSeq'] + TransTag = item['TransTag'] + AppPackId = item['AppPackId'] + sentport = item['sentport'] + rpctport = item['rpctport'] + sourceAppAddr = item['sourceAppAddr'] + targetAppAddr = item['targetAppAddr'] + TransData = { + 'ObjID': ObjID, + 'ObjLable': ObjLable, + 'TransPackID': TransPackID, + 'TransSeq': TransSeq, + 'TransTag': TransTag, + 'AppPackId': AppPackId, + 'sentport': sentport, + 'rpctport': rpctport, + 'sourceAppAddr': sourceAppAddr, + 'targetAppAddr': targetAppAddr, + 'TransPacketString': item + } + TransData_All.append(TransData) + return TransData_All + + # 建立一个函数用来处理App的解包 + def unpack_app_data(self): + ObjID = self.AppPacketString['ObjID'] + ObjLable = self.AppPacketString['ObjLable'] + AppPackId = self.AppPacketString['AppPackId'] + AppPackSize = self.AppPacketString['AppPackSize'] + AppPackTag = self.AppPacketString['AppPackTag'] + sourceAppAddr = self.AppPacketString['sourceAppAddr'] + targetAppAddr = self.AppPacketString['targetAppAddr'] + AppData = { + 'ObjID': ObjID, + 'ObjLable': ObjLable, + 'AppPackId': AppPackId, + 'AppPackSize': AppPackSize, + 'AppPackTag': AppPackTag, + 'sourceAppAddr': sourceAppAddr, + 'targetAppAddr': targetAppAddr, + 'AppPacketString': self.AppPacketString + } + # print(AppData) + return AppData + + +if __name__ == '__main__': + MacPacketString = [ + {'ObjID': 'SHO1', + 'ObjLable': 'A', + 'MAC_number': 1, + 'MacPackId': 'MacPackID1', + 'IPPackID': 'IPPack1', + 'sentmac': '00:1a:8c:10:ad:30', + 'rcptmac': '00:1a:8c:10:ad:20', + 'sourceip': '196.168.1.1', + 'targetip': '196.168.3.1', + 'sourceAppAddr': '196.168.1.1:63179', + 'targetAppAddr': '196.168.3.1:17242' + }] + + IPPacketString = [ + {'ObjID': 'SHO1', + 'ObjLable': 'A', + 'number': 1, + 'IPPackID': 'IPPack1', + 'TransPackID': 'TransPack1', + 'sourceip': '196.168.1.1', + 'targetip': '196.168.3.1', + 'sourceAppAddr': '196.168.1.1:37486', + 'targetAppAddr': '196.168.3.1:13191', + 'Mac_data': '00:1a:8c:10:ad:30'}] + + TransPacketString = [ + {'ObjID': 'SHO1', + 'ObjLable': 'A', + 'TransPackID': 'TransPack1', + 'TransSeq': '1', + 'TransTag': 'A1', + 'AppPackId': '1', + 'sentport': '41749', + 'rpctport': '20712', + 'sourceAppAddr': '196.168.1.1:41749', + 'targetAppAddr': '196.168.3.1:20712', + 'timestamp': '15:25:59', + 'Mac_data': '00:1a:8c:10:ad:30'}] + + AppPacketString = { + 'ObjID': 'SHO1', + 'ObjLable': 'A', + 'AppPackId': '1', + 'AppPackSize': 1, + 'AppPackTag': '1', + 'sourceAppAddr': '196.168.1.1:47325', + 'timeStamp': '15:22:28', + 'Mac_data': '00:1a:8c:10:ad:30', + 'targetAppAddr': '196.168.3.1:14035'} + + test_line = Unpack_All(MacPacketString,IPPacketString,TransPacketString,AppPacketString) + # test_line.unpack_mac_data() + test = test_line.unpack_app_data() + print(test) + print(test_line.unpack_trans_data()) + print(test_line.unpack_ip_data()) + print(test_line.unpack_mac_data()) + ''' + {'ObjID': 'SHO1', 'ObjLable': 'A', 'AppPackId': '1', 'AppPackSize': 1, 'AppPackTag': '1', 'sourceAppAddr': '196.168.1.1:47325', 'targetAppAddr': '196.168.3.1:14035', 'AppPacketString': {'ObjID': 'SHO1', 'ObjLable': 'A', 'AppPackId': '1', 'AppPackSize': 1, 'AppPackTag': '1', 'sourceAppAddr': '196.168.1.1:47325', 'timeStamp': '15:22:28', 'Mac_data': '00:1a:8c:10:ad:30', 'targetAppAddr': '196.168.3.1:14035'}} + [{'ObjID': 'SHO1', 'ObjLable': 'A', 'TransPackID': 'TransPack1', 'TransSeq': '1', 'TransTag': 'A1', 'AppPackId': '1', 'sentport': '41749', 'rpctport': '20712', 'sourceAppAddr': '196.168.1.1:41749', 'targetAppAddr': '196.168.3.1:20712', 'TransPacketString': {'ObjID': 'SHO1', 'ObjLable': 'A', 'TransPackID': 'TransPack1', 'TransSeq': '1', 'TransTag': 'A1', 'AppPackId': '1', 'sentport': '41749', 'rpctport': '20712', 'sourceAppAddr': '196.168.1.1:41749', 'targetAppAddr': '196.168.3.1:20712', 'timestamp': '15:25:59', 'Mac_data': '00:1a:8c:10:ad:30'}}] + [{'ObjID': 'SHO1', 'ObjLable': 'A', 'IPPackID': 'IPPack1', 'TransPackID': 'TransPack1', 'sourceip': '196.168.1.1', 'targetip': '196.168.3.1', 'sourceAppAddr': '196.168.1.1:37486', 'targetAppAddr': '196.168.3.1:13191', 'IPPacketString': {'ObjID': 'SHO1', 'ObjLable': 'A', 'number': 1, 'IPPackID': 'IPPack1', 'TransPackID': 'TransPack1', 'sourceip': '196.168.1.1', 'targetip': '196.168.3.1', 'sourceAppAddr': '196.168.1.1:37486', 'targetAppAddr': '196.168.3.1:13191', 'Mac_data': '00:1a:8c:10:ad:30'}}] + [{'ObjID': 'SHO1', 'ObjLable': 'A', 'MacPackId': 'MacPackID1', 'IPPackID': 'IPPack1', 'sentmac': '00:1a:8c:10:ad:30', 'rcptmac': '00:1a:8c:10:ad:20', 'sourceip': '196.168.1.1', 'targetip': '196.168.3.1', 'sourceAppAddr': '196.168.1.1:63179', 'targetAppAddr': '196.168.3.1:17242', 'MacPacketString': {'ObjID': 'SHO1', 'ObjLable': 'A', 'MAC_number': 1, 'MacPackId': 'MacPackID1', 'IPPackID': 'IPPack1', 'sentmac': '00:1a:8c:10:ad:30', 'rcptmac': '00:1a:8c:10:ad:20', 'sourceip': '196.168.1.1', 'targetip': '196.168.3.1', 'sourceAppAddr': '196.168.1.1:63179', 'targetAppAddr': '196.168.3.1:17242'}}] + ''' diff --git a/Internet/packet_all.py b/Internet/packet_all.py new file mode 100644 index 0000000..7bf448d --- /dev/null +++ b/Internet/packet_all.py @@ -0,0 +1,285 @@ +# 封包处理函数 +import random +import datetime + + +# 建立一个类将所有的函数放入其中 +# 将所有的主机路由器详细数据存入一个字典列表中? +# 将主机路由器的ObjID存入一个数组中通过循环来判断下一级的RctpMAC. +# MACID = ['MacA','MacR1', 'MacR2', 'MacR4', 'MacR5', 'MacD'] +# 不能将所有的函数整合成一个类 + +# 建立一个全局变量IP_number +IP_number = 0 +MAC_number = 0 + + +class AllData(): + ''' + MACID: 这个数据将从数据库simhost获取所有的数据并将每条数据中以先后组成一个mac地址数组 + ShowData: 这个数据是将数据库simhost中的所有数据组成一个字典数组从里面 + AppPackTag: 这个数据是需要用户点击前端页面的封包模拟里面输入的数据 + ''' + def __init__(self, MACID, ShowData, AppPackTag_Data): + self.MACID = MACID + self.ShowData = ShowData + self.AppPackTag_Data = AppPackTag_Data + + + def AppData(self): + MACID = self.MACID + ShowData = self.ShowData + AppPackTag_Data = self.AppPackTag_Data + # 拿到前台传过来的数据并处理 + # 将收集的数据进行处理 + ''' + test: + 这里添加一个对字典列表ShowData的for循环 + 然后对字典列表里的['ObjID']进行判断,判断是否为开始主机 + ''' + # print(len(ShowData)) + AppPackedString = {} + for i in range(0,len(ShowData)): + # print(i) + if i == 0 and ShowData[i]['ObjType'] == 1: + ObjID = ShowData[i]['ObjID'] + ObjLable = ShowData[i]['ObjLable'] + AppPackId = AppPackTag_Data['AppPackID'] + AppPackSize = AppPackTag_Data['AppPackSize'] + AppPackTag = AppPackTag_Data['AppPackTag'] + sentport = random.randint(2048, 65535) + sourceAppAddr = ShowData[i]['IPAddr'] + ':' + str(sentport) + timeStamp = datetime.datetime.now().strftime('%H:%M:%S') + Mac_data = ShowData[i]['MACAddr'] + # 对字典进行添加 + AppPackedString['ObjID'] = ObjID + AppPackedString['ObjLable'] = ObjLable + AppPackedString['AppPackId'] = AppPackId + AppPackedString['AppPackSize'] = AppPackSize + AppPackedString['AppPackTag'] = AppPackTag + AppPackedString['sourceAppAddr'] = sourceAppAddr + AppPackedString['timeStamp'] = timeStamp + AppPackedString['Mac_data'] = Mac_data + if i == (len(ShowData)-1): + rpctport = random.randint(2048, 65535) + targetAppAddr = ShowData[i]['IPAddr'] + ':' + str(rpctport) + AppPackedString['targetAppAddr'] = targetAppAddr + return AppPackedString + + def TransData(self,AppPackedString): + ''' + 这里需要处理获取的信息 + ''' + # print(AppPackedString) + AppPackSize = AppPackedString['AppPackSize'] + page_true = Spilt_AppData(AppPackSize) + # 定义一个空列表存放所有TransPackedString + TransPackedString_All = [] + # 将数据包分为page_true个传输层数据包 + for i in range(0, page_true): + num = i + 1 + # 这里需要建立一个将Trans数据封包函数 + TransPackedString = insert_TransData(num, AppPackedString) + TransPackedString_All.append(TransPackedString) + # print(TransPackedString_All) + return TransPackedString_All + + + + + + # 这里建立一个IP层封包数据函数 + def IPData(self,TransPackedString): + # 将获取的字典数组进行拆分 + IPPackedString_All = [] + for item in TransPackedString: + global IP_number + IP_number = IP_number + 1 # IP_number为记录数据经过函数IPData的次数 + ObjID = item['ObjID'] + ObjLable = item['ObjLable'] + IPPackID = 'IPPack' + str(IP_number) + TransPackID = item['TransPackID'] + sourceip_true = item['sourceAppAddr'].split(':') + sourceip = sourceip_true[0] + targetip_true = item['targetAppAddr'].split(':') + targetip = targetip_true[0] + sourceAppAddr = item['sourceAppAddr'] + targetAppAddr = item['targetAppAddr'] + Mac_data = item['Mac_data'] + IPPackedString = { + 'ObjID': ObjID, + 'ObjLable': ObjLable, + 'number': IP_number, + 'IPPackID': IPPackID, + 'TransPackID': TransPackID, + 'sourceip': sourceip, + 'targetip': targetip, + 'sourceAppAddr': sourceAppAddr, + 'targetAppAddr': targetAppAddr, + 'Mac_data': Mac_data + } + IPPackedString_All.append(IPPackedString) + return IPPackedString_All + + + '''{'ObjID': 'SHO1', 'ObjLable': 'A', 'AppPackId': 'AppPack1', 'AppPackSize': 6144, 'AppPackTag': 'A-6144-Data', 'sourceAppAddr': '196.168.1.1:35239', 'timeStamp': '13:03:25', 'Mac_data': '00:1a:8c:10:ad:30', 'targetAppAddr': '196.168.3.1:45771'} + [{'ObjID': 'SHO1', 'ObjLable': 'A', 'TransPackID': 'TransPack1', 'TransSeq': '1', 'TransTag': 'A1', 'AppPackId': 'AppPack1', 'sentport': '35239', 'rpctport': '45771', 'sourceAppAddr': '196.168.1.1:35239', 'targetAppAddr': '196.168.3.1:45771', 'timestamp': '13:03:25', 'Mac_data': '00:1a:8c:10:ad:30'}, {'ObjID': 'SHO1', 'ObjLable': 'A', 'TransPackID': 'TransPack2', 'TransSeq': '2', 'TransTag': 'A2', 'AppPackId': 'AppPack1', 'sentport': '35239', 'rpctport': '45771', 'sourceAppAddr': '196.168.1.1:35239', 'targetAppAddr': '196.168.3.1:45771', 'timestamp': '13:03:25', 'Mac_data': '00:1a:8c:10:ad:30'}, {'ObjID': 'SHO1', 'ObjLable': 'A', 'TransPackID': 'TransPack3', 'TransSeq': '3', 'TransTag': 'A3', 'AppPackId': 'AppPack1', 'sentport': '35239', 'rpctport': '45771', 'sourceAppAddr': '196.168.1.1:35239', 'targetAppAddr': '196.168.3.1:45771', 'timestamp': '13:03:25', 'Mac_data': '00:1a:8c:10:ad:30'}] + [{'ObjID': 'SHO1', 'ObjLable': 'A', 'number': 1, 'IPPackID': 'IPPack1', 'TransPackID': 'TransPack1', 'sourceip': '196.168.1.1', 'targetip': '196.168.3.1', 'sourceAppAddr': '196.168.1.1:35239', 'targetAppAddr': '196.168.3.1:45771', 'Mac_data': '00:1a:8c:10:ad:30'}, {'ObjID': 'SHO1', 'ObjLable': 'A', 'number': 2, 'IPPackID': 'IPPack2', 'TransPackID': 'TransPack2', 'sourceip': '196.168.1.1', 'targetip': '196.168.3.1', 'sourceAppAddr': '196.168.1.1:35239', 'targetAppAddr': '196.168.3.1:45771', 'Mac_data': '00:1a:8c:10:ad:30'}, {'ObjID': 'SHO1', 'ObjLable': 'A', 'number': 3, 'IPPackID': 'IPPack3', 'TransPackID': 'TransPack3', 'sourceip': '196.168.1.1', 'targetip': '196.168.3.1', 'sourceAppAddr': '196.168.1.1:35239', 'targetAppAddr': '196.168.3.1:45771', 'Mac_data': '00:1a:8c:10:ad:30'}] + [{'ObjID': 'SHO1', 'ObjLable': 'A', 'MAC_number': 1, 'MacPackId': 'MacPackID1', 'IPPackID': 'IPPack1', 'sentmac': '00:1a:8c:10:ad:30', 'rcptmac': '00:1a:8c:10:ad:30', 'sourceip': '196.168.1.1', 'targetip': '196.168.3.1', 'sourceAppAddr': '196.168.1.1:35239', 'targetAppAddr': '196.168.3.1:45771'}, {'ObjID': 'SHO1', 'ObjLable': 'A', 'MAC_number': 2, 'MacPackId': 'MacPackID2', 'IPPackID': 'IPPack2', 'sentmac': '00:1a:8c:10:ad:30', 'rcptmac': '00:1a:8c:10:ad:30', 'sourceip': '196.168.1.1', 'targetip': '196.168.3.1', 'sourceAppAddr': '196.168.1.1:35239', 'targetAppAddr': '196.168.3.1:45771'}, {'ObjID': 'SHO1', 'ObjLable': 'A', 'MAC_number': 3, 'MacPackId': 'MacPackID3', 'IPPackID': 'IPPack3', 'sentmac': '00:1a:8c:10:ad:30', 'rcptmac': '00:1a:8c:10:ad:30', 'sourceip': '196.168.1.1', 'targetip': '196.168.3.1', 'sourceAppAddr': '196.168.1.1:35239', 'targetAppAddr': '196.168.3.1:45771'}] + ''' + + # 这里建立一个MAC层封包数据函数 + # def MACData(self,IPPackedString,MACID): + def MACData(self, IPPackedString): + # 建立一个空数组用来存放所有的数据 + MacPackedString_All = [] + for item in IPPackedString: + global MAC_number + rcptmac = '' + ObjID = item['ObjID'] + ObjLable = item['ObjLable'] + MAC_number = MAC_number + 1 + MacPackId = 'MacPackID' + str(MAC_number) + IPPackID = item['IPPackID'] + sentmac = item['Mac_data'] + # 循环MACID来获取下一级rcptmac + for i in range(len(self.MACID)-1): + if sentmac == self.MACID[i]: + rcptmac = self.MACID[i+1] + + + + sourceip = item['sourceip'] + targetip = item['targetip'] + sourceAppAddr = item['sourceAppAddr'] + targetAppAddr = item['targetAppAddr'] + MacPackedString = { + 'ObjID': ObjID, + 'ObjLable': ObjLable, + 'MAC_number': MAC_number, + 'MacPackId': MacPackId, + 'IPPackID': IPPackID, + 'sentmac': sentmac, + 'rcptmac': rcptmac, + 'sourceip': sourceip, + 'targetip': targetip, + 'sourceAppAddr': sourceAppAddr, + 'targetAppAddr': targetAppAddr + } + MacPackedString_All.append(MacPackedString) + return MacPackedString_All + + + +# 建立一个使应用层数据包进行拆分的函数 +def Spilt_AppData(AppPackSize): + # 将获取的数据包大小进行拆分 + page = int(AppPackSize) / 2048 + # 定义一个初始值 + page_true = 0 + if page < 1 and page != 0: + page_true = int(page) + 1 + elif page % 1 == 0: + page_true = int(page) + elif page % 1 > 0: + page_true = int(page) + 1 + return page_true + + +# 建立一个进行TransData数据封包函数 +def insert_TransData(num, AppPackedString): + TransPackID_Riget = num + ObjID = AppPackedString['ObjID'] + ObjLable = AppPackedString['ObjLable'] + TransPackID = 'TransPack'+str(TransPackID_Riget) + TransSeq = str(TransPackID_Riget) + TransTag = AppPackedString['ObjLable']+str(TransPackID_Riget) + AppPackId = AppPackedString['AppPackId'] + sentport_one = AppPackedString['sourceAppAddr'].split(':') + # print(sentport_one) + sentport = sentport_one[1] + # print(sentport) + rpctport_one = AppPackedString['targetAppAddr'].split(':') + rpctport = rpctport_one[1] + sourceAppAddr = AppPackedString['sourceAppAddr'] + targetAppAddr = AppPackedString['targetAppAddr'] + timestamp = datetime.datetime.now().strftime('%H:%M:%S') + Mac_data = AppPackedString['Mac_data'] + TransPackedString = { + 'ObjID': ObjID, + 'ObjLable': ObjLable, + 'TransPackID': TransPackID, + 'TransSeq': TransSeq, + 'TransTag': TransTag, + 'AppPackId': AppPackId, + 'sentport': sentport, + 'rpctport': rpctport, + 'sourceAppAddr': sourceAppAddr, + 'targetAppAddr': targetAppAddr, + 'timestamp': timestamp, + 'Mac_data': Mac_data + } + # print(TransPackedString) + return TransPackedString + + + + +if __name__ == '__main__': + # 建立一个列表来存放ObjID里的MAC地址 , test + MACID = ['00:1a:8c:10:ad:30', '00:1a:8c:10:ad:30'] + # MACID = { + # 'A': 'MacA', + # 'R1': 'MacR1', + # 'R2': 'MacR2', + # 'R4': 'MacR4', + # 'R5': 'MacR5', + # 'D': 'MacD' + # } + # 定义一个数据用来模拟前台发送过来的数据:字典类型最好, test + # 这个位置需要的使一个字典列表, 至少需要两个以上的字典 + ''' + ShowData为字典数组,进行到第三步需要将数据修改进行替换, + 此数据需要前端传入后端以json格式 + ''' + # port 好需要通过random来实现 + ShowData = [ + { + 'id': 1, + 'ObjID': 'SHO1', + 'ObjType':1, + 'ObjLable': 'A', + 'IPAddr': '196.168.1.1', # 起始IP地址 + 'ObjX': 210, + 'ObjY': 130, + 'MACAddr': '00:1a:8c:10:ad:30' # test用mac地址 + }, + { + 'id': 1, + 'ObjID': 'SRO1', + 'ObjType': 2, + 'ObjLable': 'R1', + 'IPAddr': '196.168.3.1', # 最终IP地址 + 'ObjX': 210, + 'ObjY':130, + 'MACAddr': '00:1a:8c:10:ad:30' + } + ] + AppPackTag_Data = { + 'AppPackID': 'AppPack1', + 'AppPackSize': 6144, + 'AppPackTag': 'A-6144-Data' + } + # 需要定义一个最终IP地址路由节点用来进行测试 test + # 测试主程序 + AllData = AllData(MACID, ShowData, AppPackTag_Data) + test = AllData.AppData() + print(test) + test_1 = AllData.TransData(test) + print(test_1) + test_2 = AllData.IPData(test_1) + print(test_2) + print(AllData.MACData(test_2)) + ''' + 封包函数数据以全部可以获取,现在进行主机和路由器之间的交互 + ''' \ No newline at end of file diff --git a/images/主机_1.png b/images/主机_1.png new file mode 100644 index 0000000..8708a1f Binary files /dev/null and b/images/主机_1.png differ diff --git a/images/主机_2.png b/images/主机_2.png new file mode 100644 index 0000000..abc553e Binary files /dev/null and b/images/主机_2.png differ diff --git a/images/信封_1.png b/images/信封_1.png new file mode 100644 index 0000000..61da718 Binary files /dev/null and b/images/信封_1.png differ diff --git a/images/信封_2.png b/images/信封_2.png new file mode 100644 index 0000000..a0ca941 Binary files /dev/null and b/images/信封_2.png differ diff --git a/images/修改图片大小.py b/images/修改图片大小.py new file mode 100644 index 0000000..fc12df7 --- /dev/null +++ b/images/修改图片大小.py @@ -0,0 +1,11 @@ +from PIL import Image + +# 打开原始图片 +image = Image.open('路由器_1.png') + +new_width = 45 +new_height = 45 +resized_image = image.resize((new_width,new_height)) + +# 保存图片 +resized_image.save('路由器_2.png') \ No newline at end of file diff --git a/images/详情头.png b/images/详情头.png new file mode 100644 index 0000000..54b3c7c Binary files /dev/null and b/images/详情头.png differ diff --git a/images/详情头_1.png b/images/详情头_1.png new file mode 100644 index 0000000..1f47462 Binary files /dev/null and b/images/详情头_1.png differ diff --git a/images/详情头_2.png b/images/详情头_2.png new file mode 100644 index 0000000..0f0b8a1 Binary files /dev/null and b/images/详情头_2.png differ diff --git a/images/路由器_1.png b/images/路由器_1.png new file mode 100644 index 0000000..33f0202 Binary files /dev/null and b/images/路由器_1.png differ diff --git a/images/路由器_2.png b/images/路由器_2.png new file mode 100644 index 0000000..b8c9277 Binary files /dev/null and b/images/路由器_2.png differ