从脚本执行完毕后的输出中抽取netstat的信息,汇总其连接总数,连接的外部ip及状态信息汇总。第一次写时只适合在redha6.3,后来在redhat5版本时不准确,后来修改匹配。适合5及6.
#从文件按列抽取netstat -an输出信息形成列表
elif checknum == 7 and dd.find('network analysis') < 0:
if len(ddlist[4]) >=9:
netlist.append(ddlist[4].replace('::ffff:','').split(':')[0] + ' ' + ddlist[5])
netliststate.append(ddlist[5])
#elif checknum == 8 and len(re.findall('[0-9]',dd))>0:
#从生成的列表中分析连接总数,连接过来主机及连接状态分类汇总
print "the connection count is %d"%len(netlist)
for connstate in set(netliststate):
print "the connection infor sort as follow:" \
"%s,count is %d"%(connstate,netliststate.count(connstate))
for netlistsingle in set(netlist):
print "the assort infor as fllow: " \
"the (ip+status) %s,the count is %d"%(netlistsingle,netlist.count(netlistsingle))
阅读(569) | 评论(0) | 转发(0) |