300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 使用python编写一个统计局域网未关机的脚本并生成excel表格(示例代码)

使用python编写一个统计局域网未关机的脚本并生成excel表格(示例代码)

时间:2020-02-10 11:05:43

相关推荐

使用python编写一个统计局域网未关机的脚本并生成excel表格(示例代码)

后端开发|Python教程

python

后端开发-Python教程

这篇文章介绍使用python编写一个统计局域网未关机的脚本并生成excel表格(示例代码)

ip高精度定位源码,ubuntu不显示共享,只要爬虫学得好,php异构,seo排名在线lzw

#!/udict/bin/env python# -*- coding: utf_8 -*-#Date:/10/17#Author:wangpeng#blog:http://wangpengtai.import subprocessimport nmapimport time,datetimeimport xlrd,xlsxwriter,xlwtimport os,sysfrom xlutils.copy import copyfrom multiprocessing import Pooldef ip_scan(ip): global nm p = subprocess.Popen("ping -c 1 -t 1 "+ip,stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True) output = p.stdout.read() #print output #the local time dtime = time.strftime("%Y/%m/%d %X",time.localtime()) nm = nmap.PortScanner() if "100% packet loss" not in output: nm.scan(ip,arguments=-O -sS -sU -F) try: dict = {status:up,IP:ip,OS:str(nm[ip][osmatch][0][ ame]),Mac:str(nm[ip][vendor].keys()[0]),Hostname:str(nm[ip][hostnames][0][ ame]),Datetime:dtime} #print dict #addResult(dict,filename,table) #print IP:%s,dict:%s %(ip,dict) except: try:dict = {status:up,IP:ip,OS:str(nm[ip][osmatch][0][ ame]),Mac:\,Hostname:str(nm[ip][hostnames][0][ ame]),Datetime:dtime} except:dict = {status:up,IP:ip,OS:\,Mac:str(nm[ip][addresses][mac]),Hostname:str(nm[ip][hostnames][0][ ame]),Datetime:dtime}print ip #print "####error!####" #print dict#pass addResult(dict,filename,table) else: print ip:%s--->down! %ip dict = {status:down,IP:ip,OS:\,Mac:\,Hostname:\,Datetime:dtime} addResult(dict,filename,table)def count_rows(filename): data = xlrd.open_workbook(filename) table = data.sheets()[0] nrows = table.nrows return nrows#create a excel table def addResult(dict,filename,table): #pick up the key from dict and make it title to excel title = dict.keys() #sort the key title.sort() clo_num = len(dict.keys()) styleBoldRed = xlwt.easyxf(font: color-index red, bold on) headerStyle = styleBoldRed if not os.path.exists(filename): wb = xlwt.Workbook() ws = wb.add_sheet(count) for i in range(clo_num): ws.write(0,i,title[i],headerStyle) ws.write(1,i,dict[title[i]]) wb.save(table) else: oldWb = xlrd.open_workbook(table,formatting_info = True) newWb = copy(oldWb) newWs = newWb.get_sheet(0) num = count_rows(filename) for i in range(clo_num): newWs.write(num,i,dict[title[i]]) newWb.save(table) def start(): global filename global table t_date = datetime.date.today().strftime("%Y_%m_%d") t_name = eport_%s.xls %(t_date) filename = r/home/python/%s %(t_name) ip_list = [] for i in range(1,255): ip_list.append(172.20.113.+str(i)) #print ip_list print("please wait...") #计算时间 time_start=time.time() #创建线程 for ip in ip_list: # pid = os.fork() # if not pid: ip_scan(ip) #sys.exit() time_end=time.time() t=time_end-time_start print **48 print \ Time:+str(t)+s print Scan results have been saved to test.\n print **48 if __name__ == \__main__: """filename = r/home/wangpeng/python/test1.xls table = est1.xls ip_list = [172.20.113.57,172.20.113.47,172.20.113.10] for ip in ip_list: ip_scan(ip) """ start()

android按键精灵源码,vscode白色主题,ubuntu 手机摄像头,tomcat限ip,SQLite保存图片缓存,wp后台插件,自适应前端框架vue,爬虫信息抓取软件,php 图片保存,seo与站王,btc交易网站源码,javascript网页特效…,进销存 网站模板下载,jsp页面调用ssh 后台方法,winfrom文件管理系统,扫雷程序javalzw

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。