网络测试工具

工具介绍:

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

功能特点:

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…

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…

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://…

家居EDI:Hom Furniture EDI需求分析

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

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

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

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_…

Flux的三步炼丹炉——fluxgym(三):矩阵测试

前面两篇文章给大家介绍了如何准备素材和怎么炼丹&#xff0c;现在我们拿到训练完成后的多个Lora怎么才能确定哪个才是我们需要的、效果最好的呢&#xff1f;答案就是使用xyz图表测试&#xff0c;也称为矩阵测试&#xff0c;通过控制控制变量的方法对Lora模型批量生图&#xff…

利用Muduo库实现简单且健壮的Echo服务器

一、muduo网络库主要提供了两个类&#xff1a; TcpServer&#xff1a;用于编写服务器程序 TcpClient&#xff1a;用于编写客户端程序 二、三个重要的链接库&#xff1a; libmuduo_net、libmuduo_base、libpthread 三、muduo库底层就是epoll线程池&#xff0c;其好处是…

文件读写操作

写入文本文件 #include <iostream> #include <fstream>//ofstream类需要包含的头文件 using namespace std;void test01() {//1、包含头文件 fstream//2、创建流对象ofstream fout;/*3、指定打开方式&#xff1a;1.ios::out、ios::trunc 清除文件内容后打开2.ios:…

C++编程语言:抽象机制:模板(Bjarne Stroustrup)

目录 23.1 引言和概观(Introduction and Overview) 23.2 一个简单的字符串模板(A Simple String Template) 23.2.1 模板的定义(Defining a Template) 23.2.2 模板实例化(Template Instantiation) 23.3 类型检查(Type Checking) 23.3.1 类型等价(Type Equivalence) …

无人机图传模块 wfb-ng openipc-fpv,4G

openipc 的定位是为各种模块提供底层的驱动和linux最小系统&#xff0c;openipc 是采用buildroot系统编译而成&#xff0c;因此二次开发能力有点麻烦。为啥openipc 会用于无人机图传呢&#xff1f;因为openipc可以将现有的网络摄像头ip-camera模块直接利用起来&#xff0c;从而…

【JavaEE进阶】图书管理系统 - 壹

目录 &#x1f332;序言 &#x1f334;前端代码的引入 &#x1f38b;约定前后端交互接口 &#x1f6a9;接口定义 &#x1f343;后端服务器代码实现 &#x1f6a9;登录接口 &#x1f6a9;图书列表接口 &#x1f384;前端代码实现 &#x1f6a9;登录页面 &#x1f6a9;…

【算法设计与分析】实验8:分支限界—TSP问题

目录 一、实验目的 二、实验环境 三、实验内容 四、核心代码 五、记录与处理 六、思考与总结 七、完整报告和成果文件提取链接 一、实验目的 掌握分支界限求解问题的思想&#xff1b;针对不同的问题&#xff0c;能够利用分支界限法进行问题拆分和求解以及时间复杂度分析…

【Linux】opencv在arm64上提示找不到libjasper-dev

解决opencv在arm64上提示找不到libjasper-dev的问题。 本文首发于❄慕雪的寒舍 问题说明 最近我在尝试编译opencv&#xff0c;安装依赖项libjasper1和libjasper-dev的时候就遇到了这个问题。在amd64平台上&#xff0c;我们可以通过下面的命令安装&#xff08;ubuntu18.04&…

【数据结构】_时间复杂度相关OJ(力扣版)

目录 1. 示例1&#xff1a;消失的数字 思路1&#xff1a;等差求和 思路2&#xff1a;异或运算 思路3&#xff1a;排序&#xff0b;二分查找 2. 示例2&#xff1a;轮转数组 思路1&#xff1a;逐次轮转 思路2&#xff1a;三段逆置&#xff08;经典解法&#xff09; 思路3…