Created
January 6, 2017 17:10
-
-
Save azlux/315c924af4800ffbc2c91db3ab8a59bc to your computer and use it in GitHub Desktop.
Mumble ping to have users, ping and bandwidth of a server
This file contains hidden or 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
import socket | |
from struct import pack, unpack | |
import datetime | |
### | |
# Work based on https://bitbucket.org/Svedrin/k10-plugins/src/tip/BwCalc/plugin.py?fileviewer=file-view-default#cl-120 | |
### | |
def mumble_ping(host, port=64738): | |
""" <host> [<port>] | |
Ping the server and display results. | |
""" | |
try: | |
addrinfo = socket.getaddrinfo(host, port, 0, 0, socket.SOL_UDP) | |
except socket.gaierror as e: | |
print(e) | |
return | |
for (family, socktype, proto, canonname, sockaddr) in addrinfo: | |
s = socket.socket(family, socktype, proto=proto) | |
s.settimeout(2) | |
buf = pack(">iQ", 0, datetime.datetime.now().microsecond) | |
try: | |
s.sendto(buf, sockaddr) | |
except (socket.gaierror, socket.timeout) as e: | |
continue | |
try: | |
data, addr = s.recvfrom(1024) | |
except socket.timeout: | |
continue | |
r = unpack(">bbbbQiii", data) | |
version = r[1:4] | |
# https://wiki.mumble.info/wiki/Protocol | |
# r[0,1,2,3] = version | |
# r[4] = ts (indent value) | |
# r[5] = users | |
# r[6] = max users | |
# r[7] = bandwidth | |
ping = (datetime.datetime.now().microsecond - r[4]) / 1000.0 | |
if ping < 0: | |
ping += 1000 | |
print("Version :", version) | |
print("ping", ping) | |
print("users", r[5]) | |
print("max user", r[6]) | |
print("bandwidth", r[7]) | |
break | |
mumble_ping("mumble.crystalyx.net") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment