Skip to content
/ mclib Public

A Minecraft client to retrieve status information via the SLP protocol

License

Notifications You must be signed in to change notification settings

Sch8ill/mclib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mclib

Release doc Go Report Card MIT license


The mclib package provides utilities for interacting with Minecraft servers using the Minecraft protocol. It includes functionality to query Minecraft servers for status and latency information. mclib is also capable of determining the software a server is running on by using fingerprinting techniques.


Installation

To use this package in your Go project, simply install it:

go get github.com/sch8ill/mclib

Usage

StatusPing

package main

import (
	"fmt"

	"github.com/sch8ill/mclib"
)

func main() {
	client, _ := mclib.NewClient("2b2t.org")
	res, _ := client.StatusPing()

	fmt.Printf("version: %s\n", res.Version.Name)
	fmt.Printf("protocol: %d\n", res.Version.Protocol)
	fmt.Printf("online players: %d\n", res.Players.Online)
	fmt.Printf("max players: %d\n", res.Players.Max)
	fmt.Printf("sample players: %+q\n", res.Players.Sample)
	fmt.Printf("description: %s\n", res.Description.String())
	fmt.Printf("latency: %dms\n", res.Latency)
}

output

version: Velocity 1.7.2-1.20.4
protocol: 47
online players: 571
max players: 1
sample players: [{"Fit" "fdee323e-7f0c-4c15-8d1c-0f277442342a"}]
description: 2B Updated to 1.19! 2T
latency: 8ms

Fingerprint

package main

import (
	"fmt"

	"github.com/sch8ill/mclib/fingerprint"
)

func main() {
	software, _ := fingerprint.Fingerprint("localhost")
	fmt.Printf("software fingerprint: %s\n", software)
}

output

software fingerprint: craftbukkit

Further documentation can be found on pkg.go.dev.


Cli

Build

requires:

make
go >= 1.22
make build

Usage

mclib also provides a simple command line interface:

  -addr string
        the server address (default "localhost")
  -fingerprint
        whether a software fingerprint should be performed on the server (default true)
  -protocol int
        the protocol version number the client should use (default 760)
  -srv
        whether a srv lookup should be made (default true)
  -timeout duration
        the connection timeout (default 5s)

For example:

mcli --addr hypixel.net --timeout 10s

License

This package is licensed under the MIT License.