def ExceptWaring(request): context={} if PCAPS == None: context['error']="请先上传要分析的数据包!" return render(request, 'DataAnalyzer/ExceptWaring.html',context) else: Params = request.GET dataid = None if('id' in Params): dataid=int(Params['id']) host_ip = get_host_ip(PCAPS) warning_list = exception_warning(PCAPS, host_ip) warning_dict = dict() for index,war in enumerate(warning_list,1): warning_dict[""+str(index)+""] = war if len(warning_dict) == 0: context['error'] = "数据包中无异常警告!" return render(request, 'DataAnalyzer/ExceptWaring.html', context) context['waring']=warning_dict if dataid: if warning_list[int(dataid) - 1]['data']: return warning_list[int(dataid) - 1]['data'].replace('\r\n', '<br>') else: return '<center><h3>无相关数据包详情</h3></center>' else: return render(request,'DataAnalyzer/ExceptWaring.html', context)
def FlowAnalyzer(request): global PCAPS,PD # PCAPS = rdpcap('ProjectMain/Pcaps/ftp3.pcap') if PCAPS == None: context = dict() context['error']='请先上传要分析的数据包...' return render(request,"DataAnalyzer/FlowAnalyzer.html",context) else: print('******************') time_flow_dict = time_flow(PCAPS) # 时间流量图 host_ip = get_host_ip(PCAPS) # 获取抓包主机的IP data_flow_dict = data_flow(PCAPS, host_ip) # 数据流入流出统计 data_ip_dict = data_in_out_ip(PCAPS, host_ip) # 访问IP地址统计 proto_flow_dict = proto_flow(PCAPS) # 常见协议流量统计 most_flow_dict = most_flow_statistic(PCAPS, PD) # 流量最多协议数量统计 most_flow_dict = sorted(most_flow_dict.items(), key=lambda d: d[1], reverse=True) if len(most_flow_dict) > 10: most_flow_dict = most_flow_dict[0:10] most_flow_key = list() for key, value in most_flow_dict: most_flow_key.append(key) pass context = dict() context['time_flow_keys']=list(time_flow_dict.keys()) context['time_flow_values']=list(time_flow_dict.values()) context['host_ip']=host_ip context['data_flow'] = data_flow_dict context['ip_flow'] = data_ip_dict context['proto_flow'] = list(proto_flow_dict.values()) context['most_flow_key'] = most_flow_key context['most_flow_dict'] = most_flow_dict return render(request,'DataAnalyzer/FlowAnalyzer.html',context)
def SenData(request): context = {} if PCAPS == None: context['error'] = "请先上传要分析的数据包!" return render(request, 'DataExtract/SenData.html', context) else: host_ip = get_host_ip(PCAPS) sendata_list = sen_data(PCAPS, host_ip) context['sendata']=sendata_list if 'id' in request.GET: dataid = request.GET['id'] return JsonResponse({"data":sendata_list[int(dataid)-1]['data'].replace('\r\n', '<br>')}) else: return render(request,'DataExtract/SenData.html', context)
def FtpData(request): context = {} dataid=0 if PCAPS == None: context['error'] = "请先上传要分析的数据包!" return render(request, 'DataExtract/FtpData.html', context) else: host_ip = get_host_ip(PCAPS) ftpdata_list = telnet_ftp_data(PCAPS, host_ip, 21) context['ftpdata']=ftpdata_list if 'id' in request.GET: dataid = request.GET['id'] return JsonResponse({'data': ftpdata_list[int(dataid)-1]['data'].replace('\r\n', '<br>')}) else: return render(request,'DataExtract/FtpData.html',context)
def WebData(request): context = {} if PCAPS == None: context['error'] = "请先上传要分析的数据包!" return render(request, 'DataExtract/WebData.html', context) else: params=request.GET host_ip = get_host_ip(PCAPS) webdata_list = web_data(PCAPS, host_ip) context['webdata']=webdata_list if 'id' in params: dataid=params['id'] context['webdata']=webdata_list[int(dataid)-1]['data'].replace('\r\n', '<br>') return JsonResponse(context) else: return render(request,'DataExtract/WebData.html', context)
def MailData(request): context = {} if PCAPS == None: context['error'] = "请先上传要分析的数据包!" return render(request, 'DataExtract/maildata.html', context) else: params= request.GET if 'filename' in params : filename=params['filename'] host_ip = get_host_ip(PCAPS) mailata_list = mail_data(PCAPS, host_ip) context['maildata'] = mailata_list if 'id' in params : dataid = params['id'] # return mailata_list[int(dataid)-1]['data'].replace('\r\n', # '<br>') context['dataid']=dataid context['maildata'] = mailata_list[int(dataid)-1]['parse_data'] return render(request,'DataExtract/mailparsedata.html',context) else: return render(request,'DataExtract/maildata.html', context)
def IpMap(request): context = dict() global PCAPS, PD if PCAPS == None: context['error'] = "请先上传要分析的数据包..." return render(request, "DataAnalyzer/IpMap.html", context) else: myip = getmyip() # 获取本机外网IP if myip: host_ip = get_host_ip(PCAPS) ipdata = get_ipmap(PCAPS, host_ip) geo_dict = ipdata[0] ip_value_list = ipdata[1] myip_geo = get_geo(myip) # 获取经纬度 ip_value_list = [(list(d.keys())[0], list(d.values())[0].split(':')[0],list(d.values())[0].split(':')[1],geo_dict.get(list(d.keys())[0])) for d in ip_value_list] context['geo_data'] = geo_dict context['ip_value'] = ip_value_list context['mygeo'] = myip_geo return render(request, "DataAnalyzer/IpMap.html", context) else: context['error'] = '请检查连接网络情况...' return render(request, "DataAnalyzer/IpMap.html", context)