@ -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)
|
@ -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
|
||||
|
@ -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
|
@ -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
|
@ -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
|
@ -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'}}]
|
||||
'''
|
After Width: | Height: | Size: 4.5 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.4 KiB |
@ -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')
|
After Width: | Height: | Size: 766 B |
After Width: | Height: | Size: 494 B |
After Width: | Height: | Size: 354 B |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 2.6 KiB |