A high-performance, asynchronous Rust library for pinging Minecraft servers to retrieve status, players, and metadata.
✨ Features
- Asynchronous I/O: Built on top of
tokiofor maximum efficiency. - Feature Flags: Modular design with
javaandbedrockfeatures (both enabled by default). - Java & Bedrock Support: Supports pinging both Java and Bedrock (MCPE) edition servers.
- Optimized Performance: Uses
BufReader/BufWriterand zero-copy string parsing. - Robust DNS Support: Full support for SRV record resolution (
_minecraft._tcp). - Rich Metadata: Parses MOTD (plain and JSON components), player samples, versions, and ModInfo (Forge/Fabric).
- Resource Efficient: Shared DNS resolver to minimize overhead during batch pings.
- Security: Built-in IP filtering capability to prevent SSRF (Server-Side Request Forgery) attacks by blocking private or reserved IP addresses.
⚙️ Installation
Add this to your Cargo.toml:
[]
= "0.1.*"
= { = "1.0", = ["full"] }
Note: Both
javaandbedrockfeatures are enabled by default. If you only need one, you can disable the default features:[] = { = "0.1.*", = false, = ["java"] }
🚀 Quick Start
use MinecraftPinger;
use PingConfig;
use JavaPingConfig;
use Duration;
async
🛠️ Configuration
Configuration is managed via PingConfig for common properties and JavaPingConfig for Java-specific options, both utilizing the Builder pattern.
PingConfig
| Builder Method | Type | Description |
|---|---|---|
set_timeout |
Duration |
Maximum time to wait for a response. |
deny_non_public_ips |
self |
Rejects non-public IPs (e.g. 127.0.0.1, 192.168.0.1), preventing SSRF attacks. |
set_ip_filter |
Fn(IpAddr) -> bool |
Apply a custom filter to resolved IPs. Returning false blocks the connection. |
JavaPingConfig
Created using JavaPingConfig::from(&config.to_builder()) or JavaPingConfig::builder().
| Builder Method | Type | Description |
|---|---|---|
set_protocol_version |
i32 |
Protocol ID sent in the handshake. |
set_hostname |
Option<String> |
Override the hostname sent in the handshake (defaults to the IP provided). |
🚨 Error Handling
The library uses a custom PingError enum to categorize failures:
ConnectionRefused: Network-level connection issues.TimeoutError: Request exceeded the configured duration.SerializationError: Failed to parse the server's JSON response.ReadPacketError: Protocol-level parsing failure.BlockedEndpoint: The resolved IP was blocked by the configured IP filter.
📄 License
MIT