def create_table(self): try: #insert_upgrade.create_table(self.tableName) create_tb = datahanding.Sqlhanding(self.tableName) create_tb.createTable() serv_name = self.tableName + '_serv' create_tb_serv = datahanding.Sqlhanding(serv_name) create_tb_serv.createStable() except: print("表存在")
def portwebbarh(self): plt.clf() web = datahanding.Sqlhanding(self.tableName) op80num, op3306num, op8080num = web.getwebportnum() op80NUM = int(op80num[0]) op3306NUM = int(op3306num[0]) op8080NUM = int(op8080num[0]) x_data = ['80 Port', '3306 Port', '8080 Port'] y_data = [op80NUM, op3306NUM, op8080NUM] # 主机端口开放数量 bar_width = 0.5 plt.barh(y=range(len(x_data)), width=y_data, label='开放端口主机数量', color='steelblue', alpha=0.5, height=bar_width) # 在柱状图上显示具体数值,ha参数控制水平对齐方式,va参数控制垂直对齐方式 for y, x in enumerate(y_data): plt.text(x + 0.1, y - bar_width / 2, '%s' % x, ha='center', va='bottom') plt.yticks(np.arange(len(x_data)), x_data) plt.title("关于Web常用端口开启情况图") # 设置坐标名称 plt.xlabel("主机数") plt.ylabel("开启端口") # 显示图 plt.legend() plt.savefig('..\\img\\webport.jpg')
def portfilebarh(self): plt.clf() file = datahanding.Sqlhanding(self.tableName) op21num, op135num, op139num, op445num = file.getfileportnum() op21NUM = int(op21num[0]) op135NUM = int(op135num[0]) op139NUM = int(op139num[0]) op445NUM = int(op445num[0]) x_data = ['21 Port', '135 Port', '139 Port', '445 Port'] y_data = [op21NUM, op135NUM, op139NUM, op445NUM] # 主机端口开放数量 bar_width = 0.5 plt.barh(y=range(len(x_data)), width=y_data, label='开放端口主机数量', color='steelblue', alpha=0.5, height=bar_width) # 在柱状图上显示具体数值,ha参数控制水平对齐方式,va参数控制垂直对齐方式 for y, x in enumerate(y_data): plt.text(x + 0.1, y - bar_width / 2, '%s' % x, ha='center', va='bottom') plt.yticks(np.arange(len(x_data)), x_data) plt.title("关于文件共享常用端口开启情况图") # 设置坐标名称 plt.xlabel("主机数") plt.ylabel("开启端口") # 显示图 plt.legend() plt.savefig('..\\img\\fileport.jpg')
def call_do_delete(self): selection = self.table.selection() # self.flag = showinfo('提示','确认删除此信息?') # if self.flag: for item in selection: getname = self.table.item(item) do_del = datahanding.Sqlhanding(getname['values'][1]) do_del.delete_table() self.show_data()
def systempie(self): plt.clf() #win, Linux, other = datahanding.Sqlhanding.getsystemnum(self.tableName) system = datahanding.Sqlhanding(self.tableName) win, Linux, other = system.getsystemnum() sum = win + Linux + other # 显示中文 plt.rcParams['font.sans-serif'] = ['SimHei'] # 设置图饼 data = [win / sum, Linux / sum, other / sum] labels = ['Windows', 'Linux/Unix', 'Other'] explode = [0, 0, 0.3] colors = ['red', 'magenta', 'purple'] plt.axes(aspect='equal') plt.xlim(0, 8) plt.ylim(0, 8) # 绘图 plt.pie( x=data, # 绘图数据 labels=labels, # 占比标签 explode=explode, # 突出显示 colors=colors, # 图饼自定义填充色 autopct='%.3f%%', # 百分比保留数 pctdistance=0.8, # 百分比与标签距离 labeldistance=1.15, # 标签与圆心距离 startangle=180, # 饼图初始角度 center=(4, 4), # 饼图圆心 radius=3.8, # 饼图半径 counterclock=False, # 是否逆时针 wedgeprops={ 'linewidth': 1, 'edgecolor': 'green' }, # 设置饼图内外边界的属性值 textprops={ 'fontsize': 12, 'color': 'black' }, # 文本标签属性值 frame=1 # 是否显示饼图圆圈 ) # 不显示xy的刻度值 plt.xticks(()) plt.yticks(()) # 添加图形标签 plt.title(u'操作系统类型占比图') # 显示图形 plt.savefig('..\\img\\system.jpg')
def do_scan(self): self.ip = self.variable_ip.get() self.mask = self.variable_mask.get() self.Table_Name = self.variable_tab.get() dataA = datahanding.Sqlhanding(self.Table_Name) if dataA.booltable() == 1: tip = localtime + ' 与数据库表名称重叠,请重新输入。\n' self.get_tip(tip) return if self.Table_Name == '': print("Storage Name项为空,请重新输入。") tip = localtime + ' Storage Name项为空,请重新输入。\n' self.get_tip(tip) return elif self.ip == '' or self.mask == '': print("IP或MASK项为空,请重新输入。") tip = localtime + ' IP或MASK项为空,请重新输入。\n' self.get_tip(tip) return elif ipcheck.check_ip(self.ip) == False: print("输入IP项不符合规范,请重新输入。") tip = localtime + ' 输入IP项不符合规范,请重新输入。\n' self.get_tip(tip) return elif ipcheck.check_mask(self.mask) == False: print("输入MASK项不符合规范,请重新输入。") tip = localtime + ' 输入MASK项不符合规范,请重新输入。\n' self.get_tip(tip) return else: try: scan_collect.ScanCollect(self.ip, self.mask, self.Table_Name) tip = localtime + ' 扫描成功。\n' self.get_tip(tip) return except: tip = localtime + ' 扫描失败,请检查数据库。\n' self.get_tip(tip) return
def do_out_pdf(self): self.Table_Name = self.variable_tab.get() dataA = datahanding.Sqlhanding(self.Table_Name) if dataA.booltable() == 0: tip = localtime + ' 数据库表不存在,请重新输入。\n' self.get_tip(tip) return if self.Table_Name == '': print("Storage Name项为空,请重新输入。") tip = localtime + ' Storage Name项为空,请重新输入。\n' self.get_tip(tip) return else: try: # analysis_scan.export_report(self.Table_Name) analysis_scan.EXReport(self.Table_Name) tip = localtime + ' 输出' + self.Table_Name + '_Report.pdf' + '成功。\n' self.get_tip(tip) except: tip = localtime + ' 输出失败,未知错误。\n' self.get_tip(tip) return
def do_out_ex(self): self.Table_Name = self.variable_tab.get() dataA = datahanding.Sqlhanding(self.Table_Name) if dataA.booltable() == 0: tip = localtime + ' 数据库表不存在,请重新输入。\n' self.get_tip(tip) return if self.Table_Name == '': print("Storage Name项为空,请重新输入。") tip = localtime + ' Storage Name项为空,请重新输入。\n' self.get_tip(tip) return else: try: # output_excel.export_excel(self.Table_Name) exc = output_excel.ExExcel(self.Table_Name) exc.exportExcel() tip = localtime + ' 输出' + self.Table_Name + '.xls' + '成功。\n' self.get_tip(tip) except: tip = localtime + ' 输出失败,未知错误。\n' self.get_tip(tip) return
def servcloud(self): servname = self.tableName + '_serv' serv = datahanding.Sqlhanding(servname) text, num = serv.getserv() fp = open('serv.txt', 'w') for i in range(num): for j in range(10): if text[i][j] == '': pass else: newtext = text[i][j].replace(' ', '_') fp.write(newtext + ' ') fp.close() word = open('serv.txt', encoding='UTF-8').read() wordcloud = WordCloud(width=550, height=350, margin=2, background_color='black', font_path='..\\tools\\consolai.ttf') wordcloud.generate(word) wordcloud.to_file('..\\img\\serv.jpg') path = '.\\serv.txt' os.remove(path)
def html_ressult(Tabel_Name): #Tabel_Name = scan_tkinter_gui.variable_tab.get() html = open(r'..\\'+Tabel_Name+'_Report.html','w',encoding="utf-8") html.write( """ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Report</title> <style type="text/css"> h1 { font-family:宋体} div { margin:0 auto;} div.div_head{ width:100%;text-align:center;overflow-x:hidden} div.div_summary{ width:70%;overflow-y:hidden} p { font-family:宋体;font-size:14px;} table.tb{ font-family:宋体;font-size:14px;border:1px;cellpadding:5%;width:500px;margin:0 auto;text-align:center;margin-top:50px;} div.div_system{ width:500px;height:450px;margin:0 auto;margin-top:50px;} div.div_portweb{ width:550px;height:450px;margin:0 auto;margin-top:50px;} div.div_portlogin{ width:550px;height:350px;margin:0 auto;margin-top:50px;} div.div_portfile{ width:550px;height:350px;margin:0 auto;margin-top:50px;} div.div_serv{ width:550px;height:350px;margin:0 auto;margin-top:50px;} </style> </head> <body> <!--报告头部标题--> <div class="div_head"> """) html.write("<h1>%s Report</h1>"%(Tabel_Name)) html.write("""<hr style="color:black">""") localtime = time.asctime(time.localtime(time.time())) html.write("<p >报告时间:%s</p></div>"%(localtime)) html.write(""" <!--报告概述内容: 1、统计表格 2、系统饼图 3、各种类型的端口柱形图 4、服务词云图 --> <div class="div_summary"> <h3>扫描数据统计:</h3> <table class="tb" border="1"> <tr> <td>存活主机数量</td> <td>开放端口总数</td> <td>Windows主机总数</td> <td>Linux主机总数</td> <td>其他主机总数</td> </tr> """) #数据库统计存活主机------统计表格 #sum_alive = 5 #sum_alive = select_delete.get_hostnum(Tabel_Name) sum = datahanding.Sqlhanding(Tabel_Name) sum_alive = sum.queryhostnum() html.write("<tr><!--动态写入数据--><td>%s</td>"%(sum_alive)) html.write("<!--动态写入数据--><td>%s</td>"%(sum_alive)) html.write("<!--动态写入数据--><td>%s</td>"%(sum_alive)) html.write("<!--动态写入数据--><td>%s</td>"%(sum_alive)) html.write("<td>..........</td></tr></table>") html.write("<h3>可视化数据统计:</h3>") html.write(""" <div class="div_system"> <h4>图中描述本次收集的主机操作系统类型信息。</h4> <!--动态写入饼图--> """) html.write("<img src=%s width=%s height=%s /></div>"%('./img/system.jpg','500px','350px')) html.write(""" <div class="div_portweb"> <!--动态写入webport柱状图--> """) html.write("<img src=%s width=%s height=%s /></div>" % ('./img/webport.jpg', '550px', '350px')) #analysis_scan.Portlogin_barh(Tabel_Name) html.write(""" <div class="div_portlogin"> <!--动态写入loginport柱状图--> """) html.write("<img src=%s width=%s height=%s /></div>" % ('./img/loginport.jpg', '550px', '350px')) #analysis_scan.Portfile_barh(Tabel_Name) html.write(""" <div class="div_portfile"> <!--动态写入fileport柱状图--> """) html.write("<img src=%s width=%s height=%s /></div>" % ('./img/fileport.jpg', '550px', '350px')) html.write(""" <div class="div_serv"> <!--动态写入serv柱状图--> """) html.write("<img src=%s width=%s height=%s /></div>" % ('./img/serv.jpg', '550px', '350px')) html.write('</body></html>') html.close()
def do_add(self, num_i, index): self.threadLock.acquire() nm = nmap.PortScanner() try: port21_result = nm.scan( hosts=num_i, arguments='-sV -p 21' ) #-sS -Pn -n -T4 --min-hostgroup 1024 --min-parallelism 10 --host-timeout 30 port21_status = port21_result["scan"][num_i]['tcp'][21]['state'] serv21_product = port21_result["scan"][num_i]['tcp'][21]['product'] serv21_version = port21_result["scan"][num_i]['tcp'][21]['version'] serv21 = serv21_product + '' + serv21_version except: port21_status = 'close' serv21 = 'None' try: port22_result = nm.scan(hosts=num_i, arguments='-sV -p 22') port22_status = port22_result["scan"][num_i]['tcp'][22]['state'] serv22_product = port22_result["scan"][num_i]['tcp'][22]['product'] serv22_version = port22_result["scan"][num_i]['tcp'][22]['version'] serv22 = serv22_product + '' + serv22_version except: port22_status = 'close' serv22 = '' try: port23_result = nm.scan(hosts=num_i, arguments='-sV -p 23') port23_status = port23_result["scan"][num_i]['tcp'][23]['state'] serv23_product = port23_result["scan"][num_i]['tcp'][23]['product'] serv23_version = port23_result["scan"][num_i]['tcp'][23]['version'] serv23 = serv23_product + '' + serv23_version except: port23_status = 'close' serv23 = '' try: port139_result = nm.scan(hosts=num_i, arguments='-sV -p 139') port139_status = port139_result["scan"][num_i]['tcp'][139]['state'] serv139_product = port139_result["scan"][num_i]['tcp'][139][ 'product'] serv139_version = port139_result["scan"][num_i]['tcp'][139][ 'version'] serv139 = serv139_product + '' + serv139_version except: port139_status = 'close' serv139 = '' try: port3306_result = nm.scan(hosts=num_i, arguments='-sV -p 3306') port3306_status = port3306_result["scan"][num_i]['tcp'][3306][ 'state'] serv3306_product = port3306_result["scan"][num_i]['tcp'][3306][ 'product'] serv3306_version = port3306_result["scan"][num_i]['tcp'][3306][ 'version'] serv3306 = serv3306_product + '' + serv3306_version except: port3306_status = 'close' serv3306 = '' try: port3389_result = nm.scan(hosts=num_i, arguments='-sV -p 3389') port3389_status = port3389_result["scan"][num_i]['tcp'][3389][ 'state'] serv3389_product = port3389_result["scan"][num_i]['tcp'][3389][ 'product'] serv3389_version = port3389_result["scan"][num_i]['tcp'][3389][ 'version'] serv3389 = serv3389_product + '' + serv3389_version except: port3389_status = 'close' serv3389 = '' try: port8080_result = nm.scan(hosts=num_i, arguments='-sV -p 8080') port8080_status = port8080_result["scan"][num_i]['tcp'][8080][ 'state'] serv8080_product = port8080_result["scan"][num_i]['tcp'][8080][ 'product'] serv8080_version = port8080_result["scan"][num_i]['tcp'][8080][ 'version'] serv8080 = serv8080_product + '' + serv8080_version except: port8080_status = 'close' serv8080 = '' try: port445_result = nm.scan(hosts=num_i, arguments='-sV -p 445') port445_status = port445_result["scan"][num_i]['tcp'][445]['state'] serv445_product = port445_result["scan"][num_i]['tcp'][445][ 'product'] serv445_version = port445_result["scan"][num_i]['tcp'][445][ 'version'] serv445 = serv445_product + '' + serv445_version except: port445_status = 'close' serv445 = '' try: port80_result = nm.scan(hosts=num_i, arguments='-sV -p 80') port80_status = port80_result["scan"][num_i]['tcp'][80]['state'] serv80_product = port80_result["scan"][num_i]['tcp'][80]['product'] serv80_version = port80_result["scan"][num_i]['tcp'][80]['version'] serv80 = serv80_product + '' + serv80_version except: port80_status = 'close' serv80 = '' try: port135_result = nm.scan(hosts=num_i, arguments='-sV -p 135') port135_status = port135_result["scan"][num_i]['tcp'][135]['state'] serv135_product = port135_result["scan"][num_i]['tcp'][135][ 'product'] serv135_version = port135_result["scan"][num_i]['tcp'][135][ 'version'] serv135 = serv135_product + '' + serv135_version except: port135_status = 'close' serv135 = '' try: result_os = nm.scan(hosts=num_i, arguments='-O') os_status = result_os["scan"][num_i]['osmatch'][0]['name'] except: os_status = 'None' """ insert_upgrade.insert_table(self.tableName, index, num_i, os_status, port21_status, port22_status, port23_status , port80_status, port135_status, port139_status , port445_status, port3306_status, port3389_status, port8080_status) """ handing = datahanding.Sqlhanding(self.tableName) handing.insertnews(index, num_i, os_status, port21_status, port22_status, port23_status, port80_status, port135_status, port139_status, port445_status, port3306_status, port3389_status, port8080_status) handing.insertServnews(index, num_i, os_status, serv21, serv22, serv23, serv80, serv135, serv139, serv445, serv3306, serv3389, serv8080) self.threadLock.release()