Skip to content

Instantly share code, notes, and snippets.

@thoolihan
Created September 30, 2019 14:31
Show Gist options
  • Save thoolihan/68a6e7e554601db053821a309e767b79 to your computer and use it in GitHub Desktop.
Save thoolihan/68a6e7e554601db053821a309e767b79 to your computer and use it in GitHub Desktop.
A simple example using mcstatus to query a minecraft server
from mcstatus import MinecraftServer
import argparse
import json
parser = argparse.ArgumentParser()
parser.add_argument("server", help="server name or ip", nargs='?', type=str, default="localhost")
parser.add_argument("port", help="server port", nargs='?', type=int, default=25565)
args = parser.parse_args()
print("Querying server host: {} port: {}".format(args.server, args.port))
server = MinecraftServer(args.server, args.port)
status = server.status()
print("Server description: {0}".format(status.description['text']))
print("latency: {0} ms".format(status.latency))
print("version: {0}".format(status.version.name))
print("online players: {0}".format(status.players.online))
print("raw response:")
print(json.dumps(status.raw, sort_keys=True, indent = 4, separators=(',',': ')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment