IPERF+PYTHON自动生成网络状况报道,增强版杀到!!

简介: 哈哈,相比于上午的版本。 增强如下: 1,用IPERF2,MS更稳定。 2,增加HTML邮件发送,有图片,有色彩,更提醒,不同状态的机器有色彩区别。 3,相对于生成目录下的非TXT文件导致错误问题,增加排除功能。

哈哈,相比于上午的版本。

增强如下:

1,用IPERF2,MS更稳定。

2,增加HTML邮件发送,有图片,有色彩,更提醒,不同状态的机器有色彩区别。

3,相对于生成目录下的非TXT文件导致错误问题,增加排除功能。

4,计算机名更准确,不带后缀。

5,不再重复计数

。。。

计划增加:排序功能吧,IP最好也有,作成更通过吧,IPERF稳定性有问题呀。最好能更易分布到不同的服务器上,测试更彻底。

上图是王道:

 1 #!/usr/bin/env python
 2 import sys
 3 import os.path
 4 import datetime
 5 from email.mime.multipart import MIMEMultipart
 6 from email.mime.application import MIMEApplication
 7 from email.mime.text import MIMEText
 8 from email.mime.image import MIMEImage
 9 from email.utils import formatdate
10 
11 
12 folder = 'D:\Iperf\Log\\'
13 msg_low_sh = ''
14 msg_normal = ''
15 msg_low_us = ''
16 msg_nodata = ''
17 for filename in os.listdir (folder):
18     if (filename.split('.')[1] != "txt") :
19         continue
20     statinfo = os.stat(folder + filename)
21     if (statinfo.st_size == 0):
22         msg_nodata += "<tr color='#4c4c4c'  bgcolor='#4c4c4c' height = '20'><td>" + filename.split('.')[0] + "</td><td>.have now data.</td></tr>\n"
23         continue
24     fp = open(folder + filename,'r')
25     for i, line in enumerate(fp):
26         if (i == 6):
27             speednumber = line.split()
28             if (float(speednumber[5])) < 500 and (float(speednumber[5])) > 10:
29                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"
30                continue
31             if (float(speednumber[5])) <1.2:
32                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"
33                continue
34             else:
35               msg_normal +=  "<tr color=\"#036803\" bgcolor='036803' height = '20'><td>" + filename.split('.')[0] + "</td><td> Normal Speed: " + speednumber[5] + "Mbits.</td></tr>\n"
36     fp.close()
37 #print (msg_low_sh)
38 #print (msg_low_us)
39 #print (msg_normal)
40 #print (msg_nodata)
41 
42 text_file = open("LANSpeedOutput.txt", "w")
43 text_file.write('<table width="800" border="1"  bordercolor="#000000">')
44 text_file.write(msg_low_sh)
45 text_file.write(msg_low_us)
46 text_file.write(msg_normal)
47 text_file.write(msg_nodata)
48 text_file.write('</table>')
49 
50 text_file.close()
51 
52 # Define these once; use them twice!
53 strFrom = "a"
54 strTo = ["a","b","c"]
55 date = datetime.datetime.now().strftime( "%d/%m/%Y " )
56 
57 # Create the root message and fill in the from, to, and subject headers
58 msgRoot = MIMEMultipart('related')
59 msgRoot['Subject'] = "LAN Speed log at "+date
60 msgRoot['From'] = strFrom
61 msgRoot['To'] = ",".join(strTo)
62 msgRoot.preamble = 'This is a multi-part message in MIME format.'
63 
64 # Encapsulate the plain and HTML versions of the message body in an
65 # 'alternative' part, so message agents can decide which they want to display.
66 msgAlternative = MIMEMultipart('alternative')
67 msgRoot.attach(msgAlternative)
68 
69 msgText = MIMEText('This is the alternative plain text message.')
70 msgAlternative.attach(msgText)
71 
72 # We reference the image in the IMG SRC attribute by the ID we give it below
73 fptxt = open(r'LANSpeedOutput.txt', 'r')
74 msgText = MIMEText('<img src="cid:image1"><font size = 4 > Iperf Intranet Speed Report  '+ date +'</font><br>'+fptxt.read(), 'html')
75 msgAlternative.attach(msgText)
76 fptxt.close()
77 
78 # This example assumes the image is in the current directory
79 fp = open(logo.jpg', 'rb')
80 msgImage = MIMEImage(fp.read())
81 fp.close()
82 
83 # Define the image's ID as referenced above
84 msgImage.add_header('Content-ID', '<image1>')
85 msgRoot.attach(msgImage)
86 
87 # Send the email (this example assumes SMTP authentication is required)
88 import smtplib
89 smtp = smtplib.SMTP()
90 smtp.connect(‘1.2.3.4’)
91 smtp.login('a', '5678')
92 smtp.sendmail(strFrom, strTo, msgRoot.as_string())
93 smtp.quit()

 

目录
相关文章
|
机器学习/深度学习 算法 量子技术
GQNN框架:让Python开发者轻松构建量子神经网络
为降低量子神经网络的研发门槛并提升其实用性,本文介绍一个名为GQNN(Generalized Quantum Neural Network)的Python开发框架。
386 4
GQNN框架:让Python开发者轻松构建量子神经网络
|
12月前
|
运维 监控 数据可视化
Python 网络请求架构——统一 SOCKS5 接入与配置管理
通过统一接入端点与标准化认证,集中管理配置、连接策略及监控,实现跨技术栈的一致性网络出口,提升系统稳定性、可维护性与可观测性。
|
机器学习/深度学习 算法 安全
【PSO-LSTM】基于PSO优化LSTM网络的电力负荷预测(Python代码实现)
【PSO-LSTM】基于PSO优化LSTM网络的电力负荷预测(Python代码实现)
528 0
|
12月前
|
机器学习/深度学习 大数据 关系型数据库
基于python大数据的青少年网络使用情况分析及预测系统
本研究基于Python大数据技术,构建青少年网络行为分析系统,旨在破解现有防沉迷模式下用户画像模糊、预警滞后等难题。通过整合多平台亿级数据,运用机器学习实现精准行为预测与实时干预,推动数字治理向“数据驱动”转型,为家庭、学校及政府提供科学决策支持,助力青少年健康上网。
|
JSON 网络安全 数据格式
Python网络请求库requests使用详述
总结来说,`requests`库非常适用于需要快速、简易、可靠进行HTTP请求的应用场景,它的简洁性让开发者避免繁琐的网络代码而专注于交互逻辑本身。通过上述方式,你可以利用 `requests`处理大部分常见的HTTP请求需求。
960 51
基于python的网络课程在线学习交流系统
本研究聚焦网络课程在线学习交流系统,从社会、技术、教育三方面探讨其发展背景与意义。系统借助Java、Spring Boot、MySQL、Vue等技术实现,融合云计算、大数据与人工智能,推动教育公平与教学模式创新,具有重要理论价值与实践意义。
|
运维 Linux 开发者
Linux系统中使用Python的ping3库进行网络连通性测试
以上步骤展示了如何利用 Python 的 `ping3` 库来检测网络连通性,并且提供了基本错误处理方法以确保程序能够优雅地处理各种意外情形。通过简洁明快、易读易懂、实操性强等特点使得该方法非常适合开发者或系统管理员快速集成至自动化工具链之内进行日常运维任务之需求满足。
780 18
|
机器学习/深度学习 算法 PyTorch
【Pytorch框架搭建神经网络】基于DQN算法、优先级采样的DQN算法、DQN + 人工势场的避障控制研究(Python代码实现)
【Pytorch框架搭建神经网络】基于DQN算法、优先级采样的DQN算法、DQN + 人工势场的避障控制研究(Python代码实现)
337 1
|
机器学习/深度学习 算法 PyTorch
【DQN实现避障控制】使用Pytorch框架搭建神经网络,基于DQN算法、优先级采样的DQN算法、DQN + 人工势场实现避障控制研究(Matlab、Python实现)
【DQN实现避障控制】使用Pytorch框架搭建神经网络,基于DQN算法、优先级采样的DQN算法、DQN + 人工势场实现避障控制研究(Matlab、Python实现)
492 0
|
存储 监控 算法
基于 Python 跳表算法的局域网网络监控软件动态数据索引优化策略研究
局域网网络监控软件需高效处理终端行为数据,跳表作为一种基于概率平衡的动态数据结构,具备高效的插入、删除与查询性能(平均时间复杂度为O(log n)),适用于高频数据写入和随机查询场景。本文深入解析跳表原理,探讨其在局域网监控中的适配性,并提供基于Python的完整实现方案,优化终端会话管理,提升系统响应性能。
504 4

推荐镜像

更多