Created
December 1, 2018 18:02
-
-
Save lenisko/c43806e28dc2db7d1fac81348572bd3f to your computer and use it in GitHub Desktop.
Script used to send PING to Mumble server and get data
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
#!/usr/bin/python | |
""" | |
Author: @lenisko | |
Script used to send PING to Mumble server and get data: | |
- server version | |
- ping | |
- users | |
- max users | |
- bandwidth | |
""" | |
from struct import pack, unpack | |
import datetime | |
import socket | |
def mumble_info(host, port=64738): | |
# https://wiki.mumble.info/wiki/Protocol#UDP_Ping_packet | |
addr_info = socket.getaddrinfo(host, port, 0, 0, socket.SOL_UDP) | |
family, socktype, proto, _canonname, sockaddr = addr_info[0] | |
sock = socket.socket(family, socktype, proto=proto) | |
sock.settimeout(2) | |
buf = pack(">iQ", 0, datetime.datetime.now().microsecond) | |
sock.sendto(buf, sockaddr) | |
data, addr = sock.recvfrom(1024) | |
r = unpack(">bbbbQiii", data) | |
version_tuple = r[0:4] | |
ping = (datetime.datetime.now().microsecond - r[4]) / 1000.0 | |
ping += 1000 if ping < 0 else 0 | |
data = { | |
"version": ".".join(str(x) for x in version_tuple[1:]), | |
"ping": ping, | |
"users": r[5], | |
"max_users": r[6], | |
"bandwidth": r[7], | |
} | |
return data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment