首先放上c代码
/*
# This is a simple linux command line utility to execute rcon commands
# Just change the YOUR_PASSWORD_HERE to your rcon password (unless
# you want to enter it every time) and possibly change the default
# IP address from 127.0.0.1 (localhost)
#
# once downloaded on your linux system, compile it with:
#
# gcc -o rcon rcon.c
#
# note, it should work on non-linux too, but may require changing the
# socket stuff (i.e. windows will definitely need to add the winsock
# initialization line)
#
# written by [ASY]Zyrain
#
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <string.h>
#define DEBUG 0
#define SERVERDATA_EXECCOMMAND 2
#define SERVERDATA_AUTH 3
#define SERVERDATA_RESPONSE_VALUE 0
#define SERVERDATA_AUTH_RESPONSE 2
int send_rcon(int sock, int id, int command, char *string1, char *string2) {
int size, ret;
size = 10+strlen(string1)+strlen(string2);
ret = send(sock,&size,sizeof(int),0);
if(ret == -1) {
perror("send() failed:");
return -1;
}
ret = send(sock,&id,sizeof(int),0);
if(ret == -1) {
perror("send() failed:");
return -1;
}
ret = send(sock,&command,sizeof(int),0);
if(ret == -1) {
perror("send() failed:");
return -1;
}
ret = send(sock,string1,strlen(string1)+1,0);
if(ret == -1) {
perror("send() failed:");
return -1;
}
ret = send(sock,string2,strlen(string2)+1,0);
if(ret == -1) {
perror("send() failed:"