网络测试工具

工具介绍:

这是一个功能完整的网络测速工具,可以测试网络的下载速度、上传速度和延迟。

功能特点:

1. 速度测试

   - 下载速度测试

   - 上传速度测试

   - Ping延迟测试

   - 自动选择最佳服务器

2. 实时显示

   - 进度条显示测试进度

   - 实时显示测试状态

   - 清晰的数据展示

3. 历史记录

   - 保存测试历史

   - 显示最近6次测试结果

   - 支持导出历史记录

使用要求:

- Python 3.6+

- 需要安装的库:

  python -m pip install speedtest-cli

使用方法:

1. 安装依赖:

   - 首先安装必要的库

   - 确保网络连接正常

2. 开始测速:

   - 点击"开始测速"按钮

   - 等待测试完成(约1-2分钟)

   - 查看测试结果

3. 历史记录:

   - 自动保存每次测试结果

   - 查看最近的测试历史

   - 可导出完整历史记录

完整代码:

import tkinter as tk
from tkinter import ttk, messagebox
try:import speedtest
except ImportError:messagebox.showerror("错误", "请先安装 speedtest-cli:\npip install speedtest-cli")raise
import threading
import time
from datetime import datetime
import json
import os
from pathlib import Pathclass NetworkSpeedTest:def __init__(self):self.window = tk.Tk()self.window.title("网络测速工具")self.window.geometry("600x500")# 创建主框架self.main_frame = ttk.Frame(self.window, padding="10")self.main_frame.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S))# 测速结果显示self.setup_display()# 控制按钮self.setup_controls()# 历史记录self.setup_history()# 初始化speedtestself.st = Noneself.testing = Falseself.history_file = Path.home() / '.speedtest_history.json'self.load_history()def setup_display(self):# 当前速度显示display_frame = ttk.LabelFrame(self.main_frame, text="测速结果", padding="10")display_frame.grid(row=0, column=0, sticky=(tk.W, tk.E), pady=10)# 下载速度ttk.Label(display_frame, text="下载速度:").grid(row=0, column=0, pady=5)self.download_speed = ttk.Label(display_frame, text="-- Mbps")self.download_speed.grid(row=0, column=1, padx=20)# 上传速度ttk.Label(display_frame, text="上传速度:").grid(row=1, column=0, pady=5)self.upload_speed = ttk.Label(display_frame, text="-- Mbps")self.upload_speed.grid(row=1, column=1, padx=20)# Ping值ttk.Label(display_frame, text="Ping延迟:").grid(row=2, column=0, pady=5)self.ping = ttk.Label(display_frame, text="-- ms")self.ping.grid(row=2, column=1, padx=20)# 服务器信息ttk.Label(display_frame, text="测速服务器:").grid(row=3, column=0, pady=5)self.server_info = ttk.Label(display_frame, text="--")self.server_info.grid(row=3, column=1, padx=20)# 进度条self.progress = ttk.Progressbar(display_frame, length=300, mode='determinate')self.progress.grid(row=4, column=0, columnspan=2, pady=10)# 状态标签self.status = ttk.Label(display_frame, text="就绪")self.status.grid(row=5, column=0, columnspan=2)def setup_controls(self):control_frame = ttk.Frame(self.main_frame)control_frame.grid(row=1, column=0, pady=10)self.start_button = ttk.Button(control_frame, text="开始测速", command=self.start_test)self.start_button.grid(row=0, column=0, padx=5)ttk.Button(control_frame, text="导出历史", command=self.export_history).grid(row=0, column=1, padx=5)def setup_history(self):history_frame = ttk.LabelFrame(self.main_frame, text="历史记录", padding="10")history_frame.grid(row=2, column=0, sticky=(tk.W, tk.E), pady=10)# 创建表格columns = ('time', 'download', 'upload', 'ping')self.history_tree = ttk.Treeview(history_frame, columns=columns, height=6)self.history_tree.heading('time', text='时间')self.history_tree.heading('download', text='下载(Mbps)')self.history_tree.heading('upload', text='上传(Mbps)')self.history_tree.heading('ping', text='Ping(ms)')self.history_tree.column('#0', width=0, stretch=tk.NO)self.history_tree.column('time', width=150)self.history_tree.column('download', width=100)self.history_tree.column('upload', width=100)self.history_tree.column('ping', width=100)self.history_tree.grid(row=0, column=0)def load_history(self):if self.history_file.exists():try:with open(self.history_file, 'r') as f:self.history = json.load(f)self.update_history_display()except:self.history = []else:self.history = []def save_history(self):with open(self.history_file, 'w') as f:json.dump(self.history, f)def update_history_display(self):for item in self.history_tree.get_children():self.history_tree.delete(item)for record in self.history[-6:]:  # 只显示最近6条记录self.history_tree.insert('', 0, values=(record['time'],f"{record['download']:.1f}",f"{record['upload']:.1f}",f"{record['ping']:.0f}"))def start_test(self):if self.testing:returnself.testing = Trueself.start_button['state'] = 'disabled'self.progress['value'] = 0self.status['text'] = "正在初始化..."# 在新线程中运行测速threading.Thread(target=self.run_speedtest, daemon=True).start()def run_speedtest(self):try:# 初始化self.status['text'] = "正在连接到测速服务器..."self.st = speedtest.Speedtest()self.progress['value'] = 20# 选择服务器self.status['text'] = "正在选择最佳服务器..."server = self.st.get_best_server()self.server_info['text'] = f"{server['sponsor']} ({server['name']})"self.progress['value'] = 40# 测试下载速度self.status['text'] = "正在测试下载速度..."download_speed = self.st.download() / 1_000_000  # 转换为Mbpsself.download_speed['text'] = f"{download_speed:.1f} Mbps"self.progress['value'] = 60# 测试上传速度self.status['text'] = "正在测试上传速度..."upload_speed = self.st.upload() / 1_000_000  # 转换为Mbpsself.upload_speed['text'] = f"{upload_speed:.1f} Mbps"self.progress['value'] = 80# 获取ping值ping_time = server['latency']self.ping['text'] = f"{ping_time:.0f} ms"self.progress['value'] = 100# 保存结果self.history.append({'time': datetime.now().strftime("%Y-%m-%d %H:%M:%S"),'download': download_speed,'upload': upload_speed,'ping': ping_time})self.save_history()self.update_history_display()self.status['text'] = "测速完成"except Exception as e:messagebox.showerror("错误", f"测速过程中出错:{str(e)}")self.status['text'] = "测速失败"finally:self.testing = Falseself.start_button['state'] = 'normal'def export_history(self):if not self.history:messagebox.showinfo("提示", "没有历史记录可供导出")returnfile_path = tk.filedialog.asksaveasfilename(defaultextension=".csv",filetypes=[("CSV files", "*.csv")],initialfile="speedtest_history.csv")if file_path:try:with open(file_path, 'w', encoding='utf-8') as f:f.write("时间,下载速度(Mbps),上传速度(Mbps),Ping延迟(ms)\n")for record in self.history:f.write(f"{record['time']},{record['download']:.1f},"f"{record['upload']:.1f},{record['ping']:.0f}\n")messagebox.showinfo("成功", "历史记录已导出")except Exception as e:messagebox.showerror("错误", f"导出过程中出错:{str(e)}")def run(self):self.window.mainloop()if __name__ == "__main__":app = NetworkSpeedTest()app.run() 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/67695.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java每日精进1.31(SpringSecurity)

在所有的开发的系统中&#xff0c;都必须做认证(authentication)和授权(authorization)&#xff0c;以保证系统的安全性。 一、基础使用 1.依赖 <dependencies><!-- 实现对 Spring MVC 的自动化配置 --><dependency><groupId>org.springframework.bo…

简单的SQL语句的快速复习

语法的执行顺序 select 4 字段列表 from 1 表名列表 where 2 条件列表 group by 3 分组前过滤 having 分组后过滤 order by 5 排序字段列表 limit 6 分页参数 聚合函数 count 统计数量 max 最大值 min 最小值 avg 平均 sum 总和 分组查询使…

《程序人生》工作2年感悟

一些杂七杂八的感悟&#xff1a; 1.把事做好比什么都重要&#xff0c; 先树立量良好的形象&#xff0c;再横向发展。 2.职场就是人情世故&#xff0c;但也不要被人情世故绑架。 3.要常怀感恩的心&#xff0c;要记住帮助过你的人&#xff0c;愿意和你分享的人&#xff0c;有能力…

17.2 图形绘制8

版权声明&#xff1a;本文为博主原创文章&#xff0c;转载请在显著位置标明本文出处以及作者网名&#xff0c;未经作者允许不得用于商业目的。 17.2.10 重绘 先看以下例子&#xff1a; 【例 17.28】【项目&#xff1a;code17-028】绘制填充矩形。 private void button1_Clic…

自定义数据集 使用pytorch框架实现逻辑回归并保存模型,然后保存模型后再加载模型进行预测,对预测结果计算精确度和召回率及F1分数

import numpy as np import torch import torch.nn as nn import torch.optim as optim from sklearn.metrics import precision_score, recall_score, f1_score# 数据准备 class1_points np.array([[1.9, 1.2],[1.5, 2.1],[1.9, 0.5],[1.5, 0.9],[0.9, 1.2],[1.1, 1.7],[1.4,…

neo4j入门

文章目录 neo4j版本说明部署安装Mac部署docker部署 neo4j web工具使用数据结构图数据库VS关系数据库 neo4j neo4j官网Neo4j是用ava实现的开源NoSQL图数据库。Neo4作为图数据库中的代表产品&#xff0c;已经在众多的行业项目中进行了应用&#xff0c;如&#xff1a;网络管理&am…

脚本运行禁止:npm 无法加载文件,因为在此系统上禁止运行脚本

问题与处理策略 1、问题描述 npm install -D tailwindcss执行上述指令&#xff0c;报如下错误 npm : 无法加载文件 D:\nodejs\npm.ps1&#xff0c;因为在此系统上禁止运行脚本。 有关详细信息&#xff0c;请参阅 https:/go.microsoft.com/fwlink/?LinkID135170 中的 about_…

Java基础——分层解耦——IOC和DI入门

目录 三层架构 Controller Service Dao ​编辑 调用过程 面向接口编程 分层解耦 耦合 内聚 软件设计原则 控制反转 依赖注入 Bean对象 如何将类产生的对象交给IOC容器管理&#xff1f; 容器怎样才能提供依赖的bean对象呢&#xff1f; 三层架构 Controller 控制…

智慧园区系统集成解决方案引领未来城市管理的智能化转型

内容概要 在现代城市管理的背景下&#xff0c;“智慧园区系统集成解决方案”正扮演着越来越重要的角色。这种解决方案不仅仅是技术上的创新&#xff0c;更是一种全新的管理理念&#xff0c;它旨在通过高效的数据整合与分析&#xff0c;优化资源配置&#xff0c;提升运营效率。…

99.24 金融难点通俗解释:MLF(中期借贷便利)vs LPR(贷款市场报价利率)

目录 0. 承前1. 什么是MLF&#xff1f;1.1 专业解释1.2 通俗解释1.3 MLF的三个关键点&#xff1a; 2. 什么是LPR&#xff1f;2.1 专业解释2.2 通俗解释2.3 LPR的三个关键点&#xff1a; 3. MLF和LPR的关系4. 传导机制4.1 第一步&#xff1a;央行调整MLF4.2 第二步&#xff1a;银…

【VM】VirtualBox安装CentOS8虚拟机

阅读本文前&#xff0c;请先根据 VirtualBox软件安装教程 安装VirtualBox虚拟机软件。 1. 下载centos8系统iso镜像 可以去两个地方下载&#xff0c;推荐跟随本文的操作用阿里云的镜像 centos官网&#xff1a;https://www.centos.org/download/阿里云镜像&#xff1a;http://…

Elasticsearch中的度量聚合:深度解析与实战应用

在大数据和实时分析日益重要的今天&#xff0c;Elasticsearch以其强大的搜索和聚合能力&#xff0c;成为了众多企业和开发者进行数据分析和处理的首选工具。本文将深入探讨Elasticsearch中的度量聚合&#xff08;Metric Aggregations&#xff09;&#xff0c;展示其如何在数据分…

C_C++输入输出(下)

C_C输入输出&#xff08;下&#xff09; 用两次循环的问题&#xff1a; 1.一次循环决定打印几行&#xff0c;一次循环决定打印几项 cin是>> cout是<< 字典序是根据字符在字母表中的顺序来比较和排列字符串的&#xff08;字典序的大小就是字符串的大小&#xff09;…

电脑要使用cuda需要进行什么配置

在电脑上使用CUDA&#xff08;NVIDIA的并行计算平台和API&#xff09;&#xff0c;需要进行以下配置和准备&#xff1a; 1. 检查NVIDIA显卡支持 确保你的电脑拥有支持CUDA的NVIDIA显卡。 可以在NVIDIA官方CUDA支持显卡列表中查看显卡型号是否支持CUDA。 2. 安装NVIDIA显卡驱动…

深入解析:一个简单的浮动布局 HTML 示例

深入解析&#xff1a;一个简单的浮动布局 HTML 示例 示例代码解析代码结构分析1. HTML 结构2. CSS 样式 核心功能解析1. 浮动布局&#xff08;Float&#xff09;2. 清除浮动&#xff08;Clear&#xff09;3. 其他样式 效果展示代码优化与扩展总结 在网页设计中&#xff0c;浮动…

家居EDI:Hom Furniture EDI需求分析

HOM Furniture 是一家成立于1977年的美国家具零售商&#xff0c;总部位于明尼苏达州。公司致力于提供高品质、时尚的家具和家居用品&#xff0c;满足各种家庭和办公需求。HOM Furniture 以广泛的产品线和优质的客户服务在市场上赢得了良好的口碑。公司经营的产品包括卧室、客厅…

【VUE案例练习】前端vue2+element-ui,后端nodo+express实现‘‘文件上传/删除‘‘功能

近期在做跟毕业设计相关的数据后台管理系统&#xff0c;其中的列表项展示有图片展示&#xff0c;添加/编辑功能有文件上传。 “文件上传/删除”也是我们平时开发会遇到的一个功能&#xff0c;这里分享个人的实现过程&#xff0c;与大家交流谈论~ 一、准备工作 本次案例使用的…

C++中的析构器(Destructor)(也称为析构函数)

在C中&#xff0c;析构器&#xff08;Destructor&#xff09;也称为析构函数&#xff0c;它是一种特殊的成员函数&#xff0c;用于在对象销毁时进行资源清理工作。以下是关于C析构器的详细介绍&#xff1a; 析构函数的特点 名称与类名相同&#xff0c;但前面有一个波浪号 ~&a…

VLN视觉语言导航基础

0 概述 视觉语言导航模型旨在构建导航决策模型 π π π&#xff0c;在 t t t时刻&#xff0c;模型能够根据指令 W W W、历史轨迹 τ { V 1 , V 2 , . . . , V t − 1 } \tau\{V_1,V_2,...,V_{t-1}\} τ{V1​,V2​,...,Vt−1​}和当前观察 V t { P t , R t , N ( V t ) } V_…

AI协助探索AI新构型的自动化创新概念

训练AI自生成输出模块化代码&#xff0c;生成元代码级别的AI功能单元代码&#xff0c;然后再由AI组织为另一个AI&#xff0c;实现AI开发AI的能力&#xff1b;用AI协助探索迭代新构型AI将会出现&#xff0c;并成为一种新的技术路线潮流。 有限结点&#xff0c;无限的连接形式&a…