-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathdemo.py
43 lines (34 loc) · 891 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
40
41
42
43
from __future__ import print_function
import argparse
import socket
import mcrcon
# python 2 compatibility
try:
input = raw_input
except NameError:
pass
def main():
# Parse arguments
parser = argparse.ArgumentParser()
parser.add_argument("host")
parser.add_argument("port", type=int)
parser.add_argument("password")
args = parser.parse_args()
# Connect
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((args.host, args.port))
try:
# Log in
result = mcrcon.login(sock, args.password)
if not result:
print("Incorrect rcon password")
return
# Start looping
while True:
request = input()
response = mcrcon.command(sock, request)
print(response)
finally:
sock.close()
if __name__ == '__main__':
main()