From d56ea48a12e56fb6a9389926333a14c3908bcafd Mon Sep 17 00:00:00 2001 From: 6arelyFuture Date: Fri, 25 Apr 2025 18:13:55 +0000 Subject: [PATCH] feat: add rcon.py --- rcon.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 rcon.py diff --git a/rcon.py b/rcon.py new file mode 100644 index 0000000..411240e --- /dev/null +++ b/rcon.py @@ -0,0 +1,34 @@ +import socket +import sys + +if len(sys.argv) < 4: + print(f"Usage: python {sys.argv[0]} [...]") + sys.exit(1) + +# create a UDP socket +sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + +# set the address and port of the remote host +ip_address = sys.argv[1] +port = int(sys.argv[2]) +password = sys.argv[3] + +command = ' '.join(sys.argv[4:]) + +remote_address = (ip_address, port) + +# set a timeout of 5 seconds for recvfrom() +sock.settimeout(5.0) + +message = b'\xff\xff\xff\xffrcon ' + password.encode() + b' ' + command.encode() + +sock.sendto(message, remote_address) + +try: + # wait for a response from the remote host + response, remote_address = sock.recvfrom(4096) +except socket.timeout: + # handle timeout + print('Timed out while waiting for response.') +else: + print('Received: ', response)