-
Notifications
You must be signed in to change notification settings - Fork 2
/
lime_stat.py
executable file
·43 lines (38 loc) · 954 Bytes
/
lime_stat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
from __future__ import print_function
import socket
srv = ("37.187.74.33", 27015)
query = "\xFF\xFF\xFF\xFF\x54Source Engine Query\x00"
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
sock.sendto(query, srv)
rep = sock.recvfrom(4096)
except:
sock.close()
raise
# strip first \xff's
rep = rep[0][6:]
## split first text fields up to last numbers list
rep = rep.split('\x00', 5)
## get list with numbers
nums = rep[-1]
keyvals_str = nums.split('@', 2)[1]
keyvals = {}
for entry_str in keyvals_str.split(','):
entry = entry_str.split(':', 2)
if (len(entry) != 2):
print('Missmatching: %s' % entry_str)
else:
_k = entry[0].strip()
_v = entry[1].strip()
keyvals[_k] = _v
#print(keyvals)
#print(nums[0:30].encode('hex'))
#print(nums[0:30])
#
## hostname - players/maxplayers
print('%s - %s/%s' % (
rep[0],
keyvals['playersCount'],
ord(nums[2])))
#