chaospott_mumble/chaospott_mumble.py

30 lines
768 B
Python
Raw Normal View History

2021-02-11 00:00:47 +00:00
#!/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:
print("%d:NaN:NaN" % (time.time()))
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