IPERF+PYTHON自动生成网络状况报道,增强版杀到!!
2013-03-26 20:37
106 查看
哈哈,相比于上午的版本。
增强如下:
1,用IPERF2,MS更稳定。
2,增加HTML邮件发送,有图片,有色彩,更提醒,不同状态的机器有色彩区别。
3,相对于生成目录下的非TXT文件导致错误问题,增加排除功能。
4,计算机名更准确,不带后缀。
5,不再重复计数
。。。
计划增加:排序功能吧,IP最好也有,作成更通过吧,IPERF稳定性有问题呀。最好能更易分布到不同的服务器上,测试更彻底。
上图是王道:
增强如下:
1,用IPERF2,MS更稳定。
2,增加HTML邮件发送,有图片,有色彩,更提醒,不同状态的机器有色彩区别。
3,相对于生成目录下的非TXT文件导致错误问题,增加排除功能。
4,计算机名更准确,不带后缀。
5,不再重复计数
。。。
计划增加:排序功能吧,IP最好也有,作成更通过吧,IPERF稳定性有问题呀。最好能更易分布到不同的服务器上,测试更彻底。
上图是王道:
#!/usr/bin/env python import sys import os.path import datetime from email.mime.multipart import MIMEMultipart from email.mime.application import MIMEApplication from email.mime.text import MIMEText from email.mime.image import MIMEImage from email.utils import formatdate folder = 'D:\Iperf\Log\\' msg_low_sh = '' msg_normal = '' msg_low_us = '' msg_nodata = '' for filename in os.listdir (folder): if (filename.split('.')[1] != "txt") : continue statinfo = os.stat(folder + filename) if (statinfo.st_size == 0): msg_nodata += "<tr color='#4c4c4c' bgcolor='#4c4c4c' height = '20'><td>" + filename.split('.')[0] + "</td><td>.have now data.</td></tr>\n" continue fp = open(folder + filename,'r') for i, line in enumerate(fp): if (i == 6): speednumber = line.split() if (float(speednumber[5])) < 500 and (float(speednumber[5])) > 10: msg_low_sh += "<tr color=\"#ff0000\" bgcolor='ff0000' height = '20'><td>" + filename.split('.')[0] + "</td><td> Low Speed at ShangHai: " + speednumber[5] + "Mbits. We should notice this machine.</td></tr>\n" continue if (float(speednumber[5])) <1.2: msg_low_us += "<tr color=\"#ff6600\" bgcolor='ff6600' height = '20'><td>" + filename.split('.')[0] + "</td><td>Low Speed at US: " + speednumber[5] + "Mbits. We should notice this machine.</td></tr>\n" continue else: msg_normal += "<tr color=\"#036803\" bgcolor='036803' height = '20'><td>" + filename.split('.')[0] + "</td><td> Normal Speed: " + speednumber[5] + "Mbits.</td></tr>\n" fp.close() #print (msg_low_sh) #print (msg_low_us) #print (msg_normal) #print (msg_nodata) text_file = open("LANSpeedOutput.txt", "w") text_file.write('<table width="800" border="1" bordercolor="#000000">') text_file.write(msg_low_sh) text_file.write(msg_low_us) text_file.write(msg_normal) text_file.write(msg_nodata) text_file.write('</table>') text_file.close() # Define these once; use them twice! strFrom = "a" strTo = ["a","b","c"] date = datetime.datetime.now().strftime( "%d/%m/%Y " ) # Create the root message and fill in the from, to, and subject headers msgRoot = MIMEMultipart('related') msgRoot['Subject'] = "LAN Speed log at "+date msgRoot['From'] = strFrom msgRoot['To'] = ",".join(strTo) msgRoot.preamble = 'This is a multi-part message in MIME format.' # Encapsulate the plain and HTML versions of the message body in an # 'alternative' part, so message agents can decide which they want to display. msgAlternative = MIMEMultipart('alternative') msgRoot.attach(msgAlternative) msgText = MIMEText('This is the alternative plain text message.') msgAlternative.attach(msgText) # We reference the image in the IMG SRC attribute by the ID we give it below fptxt = open(r'LANSpeedOutput.txt', 'r') msgText = MIMEText('<img src="cid:image1"><font size = 4 > Iperf Intranet Speed Report '+ date +'</font><br>'+fptxt.read(), 'html') msgAlternative.attach(msgText) fptxt.close() # This example assumes the image is in the current directory fp = open(logo.jpg', 'rb') msgImage = MIMEImage(fp.read()) fp.close() # Define the image's ID as referenced above msgImage.add_header('Content-ID', '<image1>') msgRoot.attach(msgImage) # Send the email (this example assumes SMTP authentication is required) import smtplib smtp = smtplib.SMTP() smtp.connect(‘1.2.3.4’) smtp.login('a', '5678') smtp.sendmail(strFrom, strTo, msgRoot.as_string()) smtp.quit()
相关文章推荐
- 【两项业界最佳】普林斯顿新算法自动生成高性能神经网络,同时超高效压缩
- [ python3 ] 基于zabbix 自动生成xlsx监控文档
- python脚本自动生成需要文件
- [网络收集]使用ASP.net(C#)批量上传图片并自动生成缩略图,文字水印图,图片水印图
- python 自动生成100万ip列表
- python 自动生成淘宝客链接
- 【Python】自动生成命令行工具 - fire 简介
- mac os平台使用python爬虫自动下载巨潮网络文件
- DayDayUP_Python自学记录[11]_列表自动生成
- Python-根据已有的行政区域信息,自动生成exl文件
- Python――flask-sqlalchemy 自动生成符合Sqlachemy的Model:sqlautocode/sqlacodegen使用方式
- [Android实例] Android Studio插件-自动根据布局生成Activity等代码1.4 (开源)(申明:来源于网络)
- python爬虫抓取新华网新闻并自动生成word文档
- 用python+scapy生成网络数据包
- python脚本自动生成ORACLE AWR报告
- 如何利用神经网络和Python生成指定模式的密码
- 循序渐进Python3(十三) --3-- django之form表单(为自动生成的html标签添加样式)
- Python自动生成随机身份证号码
- 【Python】自动生成命令行工具 - fire 简介
- [转]python 代码自动生成的方法 (代码生成器)