python code to check internet speed

python code to check internet speed

code:

”import subprocess
import re

def get_wifi_info_robust():
# Use ‘gbk’ for Chinese Windows systems
cmd = [‘netsh’, ‘wlan’, ‘show’, ‘interfaces’]
try:
raw_output = subprocess.check_output(cmd, shell=True).decode(‘gbk’, errors=’ignore’)
except subprocess.CalledProcessError:
return “Error: Could not execute command.”

# This dictionary will hold our extracted data
wifi_data = {}

# Split the output into lines and process each one
for line in raw_output.splitlines():
# Look for the pattern: “Field : Value”
# The regex splits by the first colon found
parts = line.split(‘:’, 1)
if len(parts) == 2:
key = parts[0].strip()
value = parts[1].strip()
if key and value:
wifi_data[key] = value

return wifi_data

if __name__ == “__main__”:
data = get_wifi_info_robust()

# Print what we found
if isinstance(data, dict):
for key, value in data.items():
print(f”{key:<25}: {value}”)
else:
print(data)”

linkedin : https://www.linkedin.com/in/kadiruludag19/

Leave a Reply