Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## https://pimylifeup.com/raspberry-pi-internet-speed-monitor/
- import os
- import re
- import subprocess
- import time
- response = subprocess.Popen('/usr/bin/speedtest --accept-license --accept-gdpr', shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8')
- ping = re.search('Latency:\s+(.*?)\s', response, re.MULTILINE)
- download = re.search('Download:\s+(.*?)\s', response, re.MULTILINE)
- upload = re.search('Upload:\s+(.*?)\s', response, re.MULTILINE)
- jitter = re.search('Latency:.*?jitter:\s+(.*?)ms', response, re.MULTILINE)
- def extract_number(match):
- if match:
- value = re.search(r'\d+\.?\d*', match.group(1))
- if value:
- return float(value.group())
- return None
- ping_value = extract_number(ping)
- download_value = extract_number(download)
- upload_value = extract_number(upload)
- print("Ping: \t\t\t",ping_value, "ms")
- print("Download Speed: \t",download_value, "Mbps")
- print("Upload Speed: \t\t",upload_value, "Mbps")
Add Comment
Please, Sign In to add comment