Last active
January 23, 2026 20:32
-
-
Save bucketss/ffb10948ae80293ae2794f06bab4a4b7 to your computer and use it in GitHub Desktop.
remote rcon for goldsrc/hlds (python)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # usage: pass commands directly as arguments | |
| # examples: | |
| # python hlds_rcon.py say hello | |
| # python hlds_rcon.py changelevel de_dust2 | |
| # python hlds_rcon.py amx_kick RudePlayer02 | |
| import socket | |
| import sys | |
| def rcon(ip, port, password, command): | |
| sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
| sock.settimeout(3) | |
| sock.sendto(b"\xff\xff\xff\xffchallenge rcon\n", (ip, port)) | |
| data, _ = sock.recvfrom(4096) | |
| data = data.replace(b"\xff\xff\xff\xff", b"").strip() | |
| parts = data.split() | |
| if len(parts) < 3: | |
| raise RuntimeError(f"bad challenge response: {data!r}") | |
| challenge = parts[2] | |
| packet = ( | |
| b"\xff\xff\xff\xff" | |
| b"rcon " | |
| + challenge + b" " | |
| + password.encode("ascii", errors="ignore") + b" " | |
| + command.encode("ascii", errors="ignore") | |
| + b"\n" | |
| ) | |
| sock.sendto(packet, (ip, port)) | |
| response = b"" | |
| while True: | |
| try: | |
| chunk, _ = sock.recvfrom(4096) | |
| response += chunk | |
| except socket.timeout: | |
| break | |
| sock.close() | |
| return response.replace(b"\xff\xff\xff\xffl", b"").decode(errors="ignore") | |
| if __name__ == "__main__": | |
| # Enter server IP here in quotes e.g. "69.4.2.0" | |
| IP = "YOUR_SERVER_IP" | |
| # Enter server port here, do not use "quotes" cuz we pass as int | |
| PORT = 27015 | |
| # Enter server rcon password here in quotes e.g. "supersecretpassword123" | |
| PASSWORD = "YOUR_RCON_PASSWORD" | |
| if len(sys.argv) > 1: | |
| command = " ".join(sys.argv[1:]) | |
| else: | |
| command = "status" | |
| command = command.split(";", 1)[0] | |
| print(rcon(IP, PORT, PASSWORD, command)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment