Skip to content

Instantly share code, notes, and snippets.

Embed
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='google.com', count=10):
if platform.system() == 'Windows':
flag = '-n'
else:
flag = '-c'
result = subprocess.run(['ping', flag, str(count), url],
capture_output=True)
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