def main(): if platform.system() == "Windows": clear_str = 'cls' else: clear_str = 'clear' parser = argparse.ArgumentParser(description="Send commands to a remote Minecraft console") parser.add_argument('-ip','--host',help="IP address of the server",required=True) parser.add_argument('-p','--port',help="Port for RCON on the server",required=True) args = parser.parse_args() pw = getpass.getpass() rcon = MCRcon(args.host,int(args.port),pw) print("Type 'cls' or 'clear' to clear the screen") print("Type 'exit' or 'quit' or cntrl-c to exit") while 1: try: cmd = input('Remote Console>> ') if cmd.strip().lower() in ['cls', 'clear']: os.system(clear_str) elif cmd.strip().lower() in ['exit', 'quit']: rcon.close() exit(0) elif cmd.strip() == "": pass else: msg = rcon.send(cmd) #for line in msg.split('/'): # print(line) print(msg) except EOFError: print() exit(0)
def run_command(self, command): rcon = MCRcon(self.host, self.rcon_port, self.password) rcon.send(command) rcon.close()