Chinaunix首页 | 论坛 | 博客
  • 博客访问: 14238
  • 博文数量: 9
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 100
  • 用 户 组: 普通用户
  • 注册时间: 2016-12-21 19:54
文章分类

全部博文(9)

文章存档

2016年(9)

我的朋友

分类: 系统运维

2016-12-23 14:59:49

从脚本执行完毕后的输出中抽取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)) 
阅读(539) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~