Skip to content

Instantly share code, notes, and snippets.

@barneygale
Created September 10, 2011 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barneygale/1207956 to your computer and use it in GitHub Desktop.
Save barneygale/1207956 to your computer and use it in GitHub Desktop.
import socket
import struct
def get_info(host, port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
s.send('\xfe')
assert s.recv(1) == '\xff'
l = struct.unpack('!h', s.recv(2))[0]
d = s.recv(l*2).decode('utf-16be').split(u'\xa7')
s.close()
return {'motd': d[0],
'players': int(d[1]),
'max_players': int(d[2])}
print get_info('x.nerd.nu', 25565)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment