Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.forairan.bukprobe;
- import java.io.*;
- import java.net.InetSocketAddress;
- import java.net.Socket;
- public class Bukprobe {
- public static void main(String[] args) {
- String ip;
- int port;
- String authKey;
- System.out.println("Bukprobe - utility to test Bukquery");
- if (args.length < 3) {
- System.out.println("Usage: java Bukprobe <server ip> <server port> <auth key>");
- return;
- }
- ip = args[0];
- port = Integer.parseInt(args[1]);
- authKey = args[2];
- Socket sock = new Socket();
- try {
- sock.connect(new InetSocketAddress(ip, port));
- } catch (IOException ex) {
- System.out.println("Failed to connect to " + ip + ":" + port + "!");
- return;
- }
- BufferedWriter bw;
- BufferedReader br;
- try {
- bw = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream()));
- br = new BufferedReader(new InputStreamReader(sock.getInputStream()));
- } catch (Exception ex) {
- System.out.println("Writer/reader creation failed!");
- ex.printStackTrace();
- return;
- }
- try {
- System.out.println("Bukquery header from remote server: " + br.readLine());
- bw.write("rcon auth " + authKey + "\n");
- bw.flush();
- if (!br.readLine().equals("rcon authResponse ok")) {
- throw new IllegalStateException("Invalid authkey!");
- }
- String line = "";
- // CraftBukkit version
- bw.write("version\n");
- bw.flush();
- line = br.readLine();
- System.out.println("CraftBukkit version: " + line.replace("VERSION ", ""));
- // Online players
- bw.write("rcon who\n");
- bw.flush();
- line = br.readLine();
- System.out.println("Online players: " + line.replace("rcon who ", ""));
- // Player count
- bw.write("rcon countPlayers\n");
- bw.flush();
- line = br.readLine();
- System.out.println("Player count: " + line.split(" ")[2] + " of " + line.split(" ")[3]);
- } catch (Exception ex) {
- System.out.print("Error retrieving information from server: ");
- if (ex instanceof IllegalStateException) {
- System.out.println(ex.getMessage());
- } else {
- System.out.println();
- ex.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment