text
stringlengths
1
93.6k
def showNode(L3node,totalflow,valid,invalid,usetime,pcapNum,error,sclass,iclass):
if error:
return error+u"<br /><span style='color:red'>信息提醒:包文件读入错误,可能导入包并非是libpcap格式文件,请转化为libpcap格式后再分析或者QQ联系开发者</span>"
#print time.time()
#网页浏览[htm|js|css|jpg|png|gif|aspx|php|ico]、DNS[53]、DHCP[67-68]、Netbios[137-139]、SSDP[1900]、智能过滤
if valid==0:
return u"<br /><span style='color:red'>信息提醒:包文件没有一条完整会话->继续抓包稍后分析或者重新选择包文件</span>"
if valid==-1:
return u"<br /><span style='color:red'>信息提醒:没有选择包文件->请选择包文件</span>"
summary=[u"<table id='summary'><tr><th>分析包数量</th><th>"+str(pcapNum)+u"</th><th>负载总流量</th><th>"+calc.cflow(totalflow)+u"</th><th>总会话数</th><th>"+str(valid+invalid)+u"</th><th>有效会话数</th><th>"+str(valid)\
+u"</th><th>错包会话数</th><th>"+str(invalid)+u"</th><th>分析后特征数</th><th>"+str(len(L3node))+u"</th><th>减轻工作量</th><th>"\
+str(float("%.2f" %((valid+invalid-len(L3node))*100/float(valid+invalid))))+'%'+u"</th><th>分析所用时间</th><th>"+str(float("%.2f" %usetime))\
+u"秒</th><th>分析模式</th><th>自动归类</th><th>实时分析次数</th><th style='color:red' id='aCount'></th><th>实时分析倒计时[秒]</th><th style='color:red' id='aCountDown'></th>\
</tr></table><table id='report'><thead><tr><th></th><th><input type='checkbox' id='cAll'></th><th>连接建立时间</th><th>属性协议</th><th>流量比例[增加]</th><th>会话数</th><th>首报长度</th><th>首长范围</th>\
<th>IP范围</th><th>端口范围</th><th>特征类型</th><th>协议</th><th> 内容特征 <img class='cArrow' /></th><th>报长特征 <img class='bArrow' /></th></tr></thead>"]
#print time.time()
subsizekey={}
for key, stream in L3node.items():
if sclass=='fp':
subkey=key.split('_')[0]+key.split('_')[2]
elif sclass=='f':
subkey=stream['size']
elif sclass=='s':
subkey=len(stream['pl'])
elif sclass=='p':
subkey=int(key.split('_')[2].split('<')[0].split(' ')[0])
elif sclass=='t':
subkey=min(stream['time'])
elif sclass=='r':
subkey=stream['addsize']
if iclass=='fp':
L3node[key]['sub'].sort(key=lambda x:x[10][0],reverse=False)
elif iclass=='f':
L3node[key]['sub'].sort(key=lambda x:x[11],reverse=True)
elif iclass=='p':
L3node[key]['sub'].sort(key=lambda x:x[7],reverse=False)
elif iclass=='t':
L3node[key]['sub'].sort(key=lambda x:x[16],reverse=False)
elif iclass=='r':
L3node[key]['sub'].sort(key=lambda x:x[17],reverse=True)
#if subsizekey.has_key(subkey):
if subkey in subsizekey:
#subsizekey[subkey].append([min(stream['pl']),key])
subsizekey[subkey].append([stream['size'],key])
else:
#subsizekey[subkey]=[[min(stream['pl']),key]]
subsizekey[subkey]=[[stream['size'],key]]
#print time.time()
subsizekey=subsizekey.items()
for every in subsizekey:
every[1].sort(key=lambda x:x[0],reverse=True)
if sclass=='fp':
subsizekey.sort(key=lambda x:x[1][0][0],reverse=True)
elif sclass=='f':
subsizekey.sort(reverse=True)
elif sclass=='s':
subsizekey.sort(reverse=True)
elif sclass=='p':
subsizekey.sort(reverse=False)
elif sclass=='t':
subsizekey.sort(reverse=False)
elif sclass=='r':
subsizekey.sort(reverse=True)
'''
for x in subsizekey:
print x[0]
'''
#print time.time()
for subkey,sizekey in subsizekey:
for size,key in sizekey:
attr=key.split('_')[0]
if attr[0]=='S':
attr=u'源端'+attr[1:]
elif attr[0]=='D':
attr=u'目的'+attr[1:]
ip=key.split('_')[1]
if re.match('^A',ip):
ip=u'任意'
#pass
elif re.match('.*[0-9]A',ip):
ip=ip.split('A')[0]
elif re.match('^M',ip):
ip=u'任意[合并]'
elif re.match('^L',ip):
ip=u'任意[分离]'
elif re.match('.*[0-9]L',ip):
ip=ip.split('L')[0]+u'[分离]'
elif re.match('.*[0-9]M',ip):