chaospott_mumble/chaospott_mumble.py
2021-02-14 16:59:37 +01:00

29 lines
724 B
Python
Executable File

#!/usr/bin/env python
# -*- coding: utf-8
from struct import *
import socket, time, datetime, sys, json
try:
host = "mumble.chaospott.de"
port = 64738
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(1)
buf = pack(">iQ", 0, datetime.datetime.now().microsecond)
s.sendto(buf, (host, port))
try:
data, addr = s.recvfrom(1024)
except socket.timeout:
sys.exit()
r = unpack(">bbbbQiii", data)
version = "%d.%d.%d" % (r[1], r[2], r[3])
last_update = int(time.time())
output = { "server_version": version, "connected_users": r[5], "max_users": r[6], "bandwidth": r[7], "last_update": last_update}
print(json.dumps(output))
except:
pass