Skip to content

Commit 3dd6db8

Browse files
committed
feat: added information computer name, IP and MAC addresses
1 parent 87932ad commit 3dd6db8

File tree

1 file changed

+53
-26
lines changed

1 file changed

+53
-26
lines changed

alexs_speedtest.py

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,38 @@
33
from tkinter import messagebox
44
from tkinter import ttk
55
import speedtest as st
6+
import network_adapter_information
67

78

89
def update_progress(value, message):
9-
"""Updates the progress bar and message label."""
10+
"""Updates the progress bar and message."""
1011
progress_bar['value'] = value
1112
progress_label.config(text=f"{message} (Progress: {value}%)")
12-
root.update_idletasks() # Update the GUI
13+
root.update_idletasks() # Update the interface
1314

1415

1516
def perform_speedtest():
1617
"""Performs the speed test and updates the UI with results."""
1718
test = st.Speedtest()
1819
result_container = {}
1920

20-
# Start download speed test
21+
# Download speed test
2122
update_progress(0, "Starting download speed test...")
2223
download_thread = threading.Thread(target=test_download_speed, args=(test, result_container))
2324
download_thread.start()
24-
download_thread.join() # Wait for the download thread to finish
25+
download_thread.join() # Wait for the download test to finish
2526

2627
if 'error' in result_container:
2728
messagebox.showerror("Error", result_container['error'])
2829
return
2930

3031
download_speed = result_container['download']
3132

32-
# Prepare for upload speed test
33+
# Upload speed test
3334
update_progress(0, "Starting upload speed test...")
3435
upload_thread = threading.Thread(target=test_upload_speed, args=(test, result_container))
3536
upload_thread.start()
36-
upload_thread.join() # Wait for the upload thread to finish
37+
upload_thread.join() # Wait for the upload test to finish
3738

3839
if 'error' in result_container:
3940
messagebox.showerror("Error", result_container['error'])
@@ -46,7 +47,7 @@ def perform_speedtest():
4647

4748

4849
def test_download_speed(test, result_container):
49-
"""Tests download speed and stores the result in the result_container."""
50+
"""Tests download speed."""
5051
try:
5152
download_speed = test.download(callback=download_progress_callback)
5253
if download_speed is None:
@@ -57,7 +58,7 @@ def test_download_speed(test, result_container):
5758

5859

5960
def test_upload_speed(test, result_container):
60-
"""Tests upload speed and stores the result in the result_container."""
61+
"""Tests upload speed."""
6162
try:
6263
upload_speed = test.upload(callback=upload_progress_callback)
6364
if upload_speed is None:
@@ -68,28 +69,28 @@ def test_upload_speed(test, result_container):
6869

6970

7071
def download_progress_callback(current, total, **kwargs):
71-
"""Callback to update progress during download speed test."""
72+
"""Updates progress during the download speed test."""
7273
if total > 0: # Avoid division by zero
7374
percentage = int((current / total) * 100)
7475
update_progress(percentage, "Testing download speed...")
7576

7677

7778
def upload_progress_callback(current, total, **kwargs):
78-
"""Callback to update progress during upload speed test."""
79+
"""Updates progress during the upload speed test."""
7980
if total > 0: # Avoid division by zero
8081
percentage = int((current / total) * 100)
8182
update_progress(percentage, "Testing upload speed...")
8283

8384

8485
def display_results(down_speed, up_speed, ping):
85-
"""Displays the speed test results in the UI."""
86+
"""Displays the results of the speed test in the interface."""
8687
result_text = (
8788
f"Download speed: {down_speed} Mbps\n"
8889
f"Upload speed: {up_speed} Mbps\n"
8990
f"Ping: {ping} ms"
9091
)
9192
result_label.config(text=result_text)
92-
update_progress(100, "Test complete!") # Set progress bar to 100%
93+
update_progress(100, "Test complete!") # Set progress to 100%
9394

9495
# Show "Repeat Speed Test" button and hide the exit button
9596
repeat_button.pack(pady=10)
@@ -101,43 +102,69 @@ def start_speedtest():
101102
start_button.pack_forget() # Hide the start button
102103
repeat_button.pack_forget() # Hide the repeat button if it was visible
103104

104-
# Run the speed test in a separate thread
105+
# Show progress bar
106+
progress_label.pack(pady=10)
107+
progress_bar.pack(pady=20)
108+
109+
# Start the speed test in a separate thread
105110
threading.Thread(target=perform_speedtest).start()
106111

112+
# Get and display system information
113+
display_system_info()
114+
115+
116+
def display_system_info():
117+
"""Displays system information in the interface."""
118+
info = network_adapter_information.get_network_info()
119+
120+
info_text = f"Computer Name: {info['Computer Name']}"
121+
info_text += "\nAdapters:\n"
122+
123+
for adapter in info['Adapters']:
124+
info_text += f"- Adapter: {adapter['Adapter']}\n"
125+
info_text += f"- IP Address: {adapter['IP Address']}\n"
126+
info_text += f"- MAC Address: {adapter['MAC Address']}\n"
127+
128+
system_info_label.config(text=info_text)
129+
107130

108131
def exit_program():
109-
"""Exits the application."""
132+
"""Closes the program."""
110133
root.quit()
111134

112135

113-
# Create the main window
136+
# Create main window
114137
root = tk.Tk()
115138
root.title("Internet Speed Test")
116-
root.geometry("400x400")
139+
root.geometry("400x450")
117140

118-
# Create the start button
141+
# Button to start speed test
119142
start_button = tk.Button(root, text="Start Speed Test", command=start_speedtest)
120143
start_button.pack(pady=20)
121144

122-
# Create a repeat button that will be shown after the first test
145+
# Button to repeat speed test
123146
repeat_button = tk.Button(root, text="Repeat Speed Test", command=start_speedtest)
124-
repeat_button.pack_forget() # Initially hide the repeat button
147+
repeat_button.pack_forget() # Initially hidden
125148

126-
# Create a label to display results
149+
# Label to display results
127150
result_label = tk.Label(root, text="")
128151
result_label.pack(pady=20)
129152

130-
# Create a label to show progress
153+
# Label to display progress
131154
progress_label = tk.Label(root, text="")
132-
progress_label.pack(pady=10)
155+
# Initially, progress is not visible
133156

134-
# Create a progress bar
157+
# Progress bar
135158
progress_bar = ttk.Progressbar(root, length=300, mode='determinate')
136-
progress_bar.pack(pady=20)
159+
# Initially, progress is not visible
160+
161+
# Label to display system information
162+
system_info_label = tk.Label(root, text="", justify="left", anchor="w")
163+
system_info_label.pack(pady=10, padx=20)
137164

138-
# Create a button to exit the program
165+
# Exit button
139166
exit_button = tk.Button(root, text="Exit", command=exit_program)
140-
exit_button.pack(pady=10)
167+
exit_button.pack(side="bottom", pady=10)
141168

142169
# Run the application
143170
root.mainloop()

0 commit comments

Comments
 (0)