網絡測試工具

工具介紹:

這是一個功能完整的網絡測速工具,可以測試網絡的下載速度、上傳速度和延遲。

功能特點:

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.pswp.cn/web/67695.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/67695.shtml
英文地址,請注明出處:http://en.pswp.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…