Last active
August 23, 2023 11:57
-
-
Save Talon876/2f79b5b3ddfb0ba8ae00ccd7e67766f7 to your computer and use it in GitHub Desktop.
OSRS World Ping Checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import subprocess as sp | |
import multiprocessing as mp | |
from collections import OrderedDict | |
try: | |
import tabulate | |
except: | |
tabulate = None | |
def ping_world(n): | |
url = 'oldschool{}.runescape.com'.format(n) | |
devnull = open(os.devnull, 'w') | |
try: | |
#print('Checking ping to {}'.format(url)) | |
resp = sp.check_output(['ping', '-c', '4', url], stderr=devnull).decode() | |
last_line = resp.split(os.linesep)[-2] | |
values = last_line.split(' ')[3].split('/') | |
return OrderedDict([ | |
('world', n), | |
('avg', int(float(values[1]))), | |
('min', int(float(values[0]))), | |
('max', int(float(values[2]))), | |
]) | |
except: | |
return OrderedDict([ | |
('world', n), | |
('min', -1), | |
('max', -1), | |
('avg', -1), | |
]) | |
worlds = list(range(1, 72)) | |
worlds += list(range(73, 78)) | |
worlds += list(range(81, 96)) | |
worlds += [115, 116, 120, 121, 122, 124] | |
f2p = [1, 8, 16, 26, 35, 71, 81, 82, 83, 84, 85, 93, 94, 117, 118, 119] | |
worlds = [w for w in worlds if w not in f2p] | |
print('Checking ping to {} worlds'.format(len(worlds))) | |
pool = mp.Pool(16) | |
results = pool.map(ping_world, worlds) | |
results = [r for r in results if r['avg'] != -1] | |
results = sorted(results, key=lambda w: w['avg']) | |
if tabulate: | |
print(tabulate.tabulate(results, headers='keys')) | |
else: | |
for r in results[:5]: | |
print('World {world}, Average Ping {avg}ms'.format(**r)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment