#!/usr/bin/python # This script can send rcon command to Hl server # Ce script permet d'envoyer des commandes rcon a un serveur de jeux Half-life HOST = "127.0.0.1" # The ip of the server PORT = 27015 # The port of game server (27015 is standard) RCON_PASSWORD="" #The rcon password from socket import * # Retourne les infos sur le serveur # data contient ce qui a ete envoye par le serveur # identifiant ce qui precede la donne recherche # nb si on doit retourner un nombre ou on/off def serv_info(data,identifiant,nb): try: variable=data.split("\\%s\\" % identifiant)[1].split("\\")[0] except: variable=None if nb==0: if variable=="1": variable="On" else: variable="Off" return variable print '\nPyrcon by Noplay\n\nLast version: http://www.noplay.net\n' if HOST=="": HOST=raw_input('Host:') if PORT=='': PORT=input('Port:') if RCON_PASSWORD=="": RCON_PASSWORD=raw_input('Rcon_password') s = socket(AF_INET,SOCK_DGRAM)#definition du socket s.connect((HOST,PORT))# connexion #envoie de la commande pour recuperer les infos du serveur s.send('\377\377\377\377infostring\n') data = s.recv(PORT) # On recupere les donnees # On affiche les informations sur le serveur identifiant = "hostname" hostname = serv_info(data,identifiant,1) print "Hostname:",hostname identifiant = "os" os = serv_info(data,identifiant,1) if os=="l": os="Linux" else: os="Windows" print "Os:",os identifiant = "type" dedicated = serv_info(data,identifiant,1) if dedicated=="l": dedicated="Listen" else: dedicated="Dedicated" print "Type:",dedicated identifiant = "lan" lan = serv_info(data,identifiant,0) print "Lan:",lan identifiant = "description" mod = serv_info(data,identifiant,1) print "Mod:",mod identifiant = "map" map = serv_info(data,identifiant,1) print "Map:",map identifiant = "players" nbplayer = serv_info(data,identifiant,1) identifiant = "max" playermax = serv_info(data,identifiant,1) print "Players:",nbplayer,"/",playermax identifiant = "password" password = serv_info(data,identifiant,0) print "Password:",password identifiant = "secure" secure = serv_info(data,identifiant,0) print "Valve anticheat system:",secure #Recuperation du numero de session rcon s.send('\377\377\377\377challenge rcon\n') data = s.recv(PORT) rcon_number=data[19:] rcon_number=rcon_number[:-2] print 'Rcon number:',rcon_number #Test du pass rcon rcon_command='\377\377\377\377rcon %(rcon_number)s \"%(RCON_PASSWORD)s\" echo Pyrcon test'% locals() s.send(rcon_command) data = s.recv(PORT) if data[5:16]!='Pyrcon test': print "Bad Rcon password!" else: #Le mot de passe est correct et on peut envoyer des commandes print "Good Rcon password!" command=None while data == "": data = s.recv(PORT) print data[5:] while command != "pyrcon": command=raw_input("Rcon command:") if command=='players' or command=='rules' or command=='info' or command=='details': rcon_command='\377\377\377\377%(command)s'% locals() else: rcon_command='\377\377\377\377rcon %(rcon_number)s \"%(RCON_PASSWORD)s\" %(command)s'% locals() s.send(rcon_command) data = s.recv(PORT) print data[5:] s.close() #fermeture du socket