Skip to content
/ rcon Public

A RCON client for executing commands on a remote RCON server

License

Notifications You must be signed in to change notification settings

Sch8ill/rcon

Repository files navigation

rcon

Go Report Card

A RCON client for executing commands on a remote RCON server.

This Go-based RCON client allows Minecraft server administrators to send commands to their server over a remote RCON connection. With this client, you can easily send commands and view output on the console without having to log in directly to the server.

This client implements the RCON protocol used by Minecraft servers and has the potential to work with other game servers as well, though it hasn't been extensively tested with them.

To use the client, you will need to have access to the server's RCON password and IP address/hostname. Once connected, you can send commands through the client's terminal interface and receive output on the console like you would with the standard Minecraft server console.

Installation

Prebuild

Download the latest build for your platform from the latest release

Build

You can also build your own executable. This requires:

git
go v1.18 or higher
make

Run these commands to build the executable:

git clone https://github.com/Sch8ill/rcon
make -C rcon
mv rcon/build/rcon-cli rcon-cli
rm -rf rcon

Usage

CLI

USAGE:
   rcon [global options] command [command options] [arguments...]

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --address value, -a value   address of the server you want to connect to (localhost:25575 for example) (default: "localhost")
   --password value, -p value  password of the RCON server you want to connect to (default: "minecraft")
   --command value, -c value   a single command to be executed
   --timeout value, -t value   timeout for the connection to the server (default: 7s)
   --no-colors, --no-colours   if the cli should not output colors (default: false)
   --help, -h                  show help
   --version, -v               print the version

Example commands

Move into the directory of the executable and open up a terminal.

Open up an interactive RCON terminal:

./rcon-cli -a <the-servers-address> -p <the-servers-password>

Run a single command on the server:

./rcon-cli -a <the-servers-address> -p <the-servers-password> -c <the-command-that-shall-be-executed>

Take a look at the other command flags for more features.

Environment Variables

Instead of specifying command line options each time, you can also use environment variables to set the default values. Environment variables are automatically checked and used if available. Environment variables take precedence over the default values.

Available environment variables:

DEFAULT_RCON_ADDRESS: Address of the server you want to connect to. DEFAULT_RCON_PASSWORD: Password of the RCON server you want to connect to. DEFAULT_RCON_TIMEOUT: Default timeout for the connection to the server. Example:

export DEFAULT_RCON_ADDRESS="my-server:25575"
export DEFAULT_RCON_PASSWORD="my-password"
export DEFAULT_RCON_TIMEOUT="10s"

Libary usage

Install the module using:

go get github.com/sch8ill/rcon

Import it:

import "github.com/sch8ill/rcon"

Create a new RCON client:

client, err := rcon.Dial("localhost", "password", 5) // address, password, timeout
if err != nil {
  panic(err)
}

Execute a command over RCON:

output, err := client.ExecuteCmd("some-command")
if err != nil {
  panic(err)
}

fmt.Println(output)