Skip to content

Instantly share code, notes, and snippets.

@tjb0607
Created July 27, 2012 18:47
Show Gist options
  • Save tjb0607/3189741 to your computer and use it in GitHub Desktop.
Save tjb0607/3189741 to your computer and use it in GitHub Desktop.
#!/bin/env python2
import socket
import time
def get_info(host, port):
#Start the timer
start = time.time()
#Set up our socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
#Send 0xFE: Server list ping
s.send('\xfe')
#Read as much data as we can (max packet size: 241 bytes)
d = s.recv(256)
s.close()
#Check we've got a 0xFF Disconnect
assert d[0] == '\xff'
#Remove the packet ident (0xFF) and the short containing the length of the string
#Decode UCS-2 string
#Split into list
d = d[3:].decode('utf-16be').split(u'\xa7')
#Get the ping
ping = 0.0
ping = time.time() - start
ping = ping * 1000
#Return a dict of values
return {'motd': d[0],
'players': int(d[1]),
'max_players': int(d[2]),
'ping': int(ping)}
def print_info(host, port):
info = get_info(host, port)
print '%s: %d/%d %d ms' % (info['motd'], info['players'], info['max_players'], info['ping'])
a = 1
while a < 13:
print_info('us%d-public.minez.net' % a , 25565)
a += 1
print_info('eu1-public.minez.net', 25565)
a = 1
while a < 10:
print_info('us%d.minez.net' % a , 25565)
a += 1
print_info('eu1.minez.net', 25565)
print_info('eu2.minez.net', 25565)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment