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

发布时间:2022-01-15 14:55:50 作者:柒染
来源:亿速云 阅读:148

如何批量检测主机IP并把结果生成excel文件表格,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

这是对上一个脚本的扩展,增加了生成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')

看完上述内容,你们掌握如何批量检测主机IP并把结果生成excel文件表格的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

推荐阅读:
  1. 批量生成符合规则的excel条目内容
  2. 批量生成nagios监控主机

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ip excel

上一篇:EOS怎么部署智能合约

下一篇:springboot整合quartz定时任务框架的方法是什么

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》