feat: add rcon.py
This commit is contained in:
parent
98e71cb26a
commit
d56ea48a12
34
rcon.py
Normal file
34
rcon.py
Normal file
@ -0,0 +1,34 @@
|
||||
import socket
|
||||
import sys
|
||||
|
||||
if len(sys.argv) < 4:
|
||||
print(f"Usage: python {sys.argv[0]} <ip_address> <port> <password> [<command>...]")
|
||||
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)
|
Loading…
x
Reference in New Issue
Block a user