Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Test if our ping is good enough to play Rocket League
import platform
import re
import subprocess
from statistics import mean
def pings(*, url='', count=10):
if platform.system() == 'Windows':
flag = '-n'
flag = '-c'
result =['ping', flag, str(count), url],
match = re.findall(r'time=([\d.]+)', str(result.stdout))
return sorted(float(n) for n in match)
def diagnose(ping):
# TODO: Packet loss.
errors = []
if ping[-1] - ping[0] >= 20:
errors.append('Latency Variation')
if ping[-1] >= 100:
errors.append('High Latency')
return errors
if __name__ == '__main__':
ping = pings()
errors = diagnose(ping)
print(f'Min = {ping[0]} ms, Max = {ping[-1]} ms, Avg = {mean(ping):.2f} ms')
if errors:
print(f"Errors: {', '.join(errors)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment