ITPub博客

首页 > 自动化运维 > 大规模网络运维 > 批量检测主机IP,并把结果生成excel文件表格

批量检测主机IP,并把结果生成excel文件表格

原创 大规模网络运维 作者:king3171 时间:2020-06-19 14:52:11 0 删除 编辑

这是对上一个脚本的扩展,增加了生成excel表格

#coding=gbk

import os

import sys

import xlwt

wk = xlwt.Workbook(encoding = 'utf-8')

sheet1 = wk.add_sheet("IP62",cell_overwrite_ok=True)

style = xlwt.XFStyle()

sheet1.write(0, 0,'ip地址',style)

sheet1.write(0,1, '状态',style)

x = y = 0

for ip in range(1,255):

    res = os.system('ping -n 1 -w 1 '+sys.argv[1]+str(ip))

    if res == 0:

        print(sys.argv[1]+str(ip)+' up')

        sheet1.write(ip,0,sys.argv[1]+str(ip))

        sheet1.write(ip,1,'up')

        x += 1

    else:

        print(sys.argv[1]+str(ip)+' down')

        sheet1.write(ip,0,sys.argv[1]+str(ip))

        sheet1.write(ip,1,'down')

        y += 1

print('total up ip is '+str(x))

print('total down ip is '+str(y))

sheet1.write(ip+1,0,'total up ip is '+str(x))

sheet1.write(ip+2,0,'total down ip is '+str(y))

wk.save('ip.xls')


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/51077/viewspace-2699438/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-08-03

  • 博文量
    20
  • 访问量
    14954