safwan092

Untitled

Nov 14th, 2023
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. ## https://pimylifeup.com/raspberry-pi-internet-speed-monitor/
  2.  
  3. import os
  4. import re
  5. import subprocess
  6. import time
  7. response = subprocess.Popen('/usr/bin/speedtest --accept-license --accept-gdpr', shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8')
  8.  
  9. ping = re.search('Latency:\s+(.*?)\s', response, re.MULTILINE)
  10. download = re.search('Download:\s+(.*?)\s', response, re.MULTILINE)
  11. upload = re.search('Upload:\s+(.*?)\s', response, re.MULTILINE)
  12. jitter = re.search('Latency:.*?jitter:\s+(.*?)ms', response, re.MULTILINE)
  13.  
  14. def extract_number(match):
  15. if match:
  16. value = re.search(r'\d+\.?\d*', match.group(1))
  17. if value:
  18. return float(value.group())
  19. return None
  20.  
  21. ping_value = extract_number(ping)
  22. download_value = extract_number(download)
  23. upload_value = extract_number(upload)
  24.  
  25. print("Ping: \t\t\t",ping_value, "ms")
  26. print("Download Speed: \t",download_value, "Mbps")
  27. print("Upload Speed: \t\t",upload_value, "Mbps")
Add Comment
Please, Sign In to add comment