forked from barneygale/MCRcon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
39 lines (28 loc) · 807 Bytes
/
demo.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
import mcrcon
# python 2 compatibility
try: input = raw_input
except NameError: pass
def main(host, port, password):
rcon = mcrcon.MCRcon()
print("# connecting to %s:%i..." % (host, port))
rcon.connect(host, port)
print("# logging in...")
rcon.login(password)
print("# ready")
try:
while True:
response = rcon.command(input('> '))
if response:
print(" %s" % response)
except KeyboardInterrupt:
print("\n# disconnecting...")
rcon.disconnect()
if __name__ == '__main__':
import sys
args = sys.argv[1:]
if len(args) != 3:
print("usage: python demo.py <host> <port> <password>")
sys.exit(1)
host, port, password = args
port = int(port)
main(host, port, password)