Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Minecraft server spy

Minecraft server spy is a simple utility for monitoring player connections on a Minecraft server and reporting changes to Discord. Before you use it make sure you have permition from the server owner and/or its players.

Usage

  1. Create config.json (use template in config_template.py for reference) and add your report points (discord bot/webhook)
  2. If you want to use discord bot, create .dicord_token.key and paste your discord bot token there.
  3. Install required python packages using pip: mcstatus, discord, aiohttp.
    pip install -r requirements.txt or pip3 install -r requirements.txt
  4. Run scipt: python minecraft_spy_bot.py or python3 minecraft_spy_bot.py or py minecraft_spy_bot.py
  5. (Optional, Linux only, for systemd) Setup systemd service that runs the script on startup using: sudo python setup_service.py

Config

You will need to create config.json in order to run the program, the easiest way is to copy config_template.json and tweak it.
Here is explanation of the config:

{
    "minecraft_server_url":MINECRAFT_SERVER_URL,    // Target url or IP address
    "minecraft_server_port":25565,                  // Minecraft server's port, 25565 id default
    "IDLE_CHECK_DELAY": 120,                        // How often check minecraft server when noone is connected
    "ACTIVE_CHECK_DELAY": 15,                       // How often check minecraft server when someone is connected
    "INACTIVITY_THRESHOLD_SECONDS": 300,            // How long has the server be empty in order to use 'IDLE_CHECK_DELAY' instead of 'ACTIVE_CHECK_DELAY'
    "online_check_reference":"https://google.com",  // If this website is unreachable, the program declares internet connection loss
    "report_targets":[                              // Here, messages will be sent when list of connected players changes, or the server goes online/offline
        {"target_type":"USER", "target_id":USER_ID},
        {"target_type":"CHANNEL", "target_id":CHANNEL_ID},
        {"target_type":"WEBHOOK", "bot_name":SHOWN_NAME, "target_id":WEBHOOK_URL}
    ],
    "ip_tracker":{                                  // Useful when this program is hosted on the same network/computer as the minecraft server it is tracking and the public IP address is dynamic 
        "track_my_ip_changes":false,                // Track my IP changes? Enables this feature. Useful when this program is hosted on same machine as the minecraft server it's tracking and the IP address is dynamic 
        "my_ip_change_check_delay_seconds":120,
        "my_ip_reference":"https://ident.me",       // API to get my public IP
        "report_targets":[                          // Here, messages will be sent when IP changes, you can add more targets of the same type
            {"target_type":"USER", "target_id":USER_ID},
            {"target_type":"CHANNEL", "target_id":CHANNEL_ID},
            {"target_type":"WEBHOOK", "bot_name":SHOWN_NAME, "target_id":WEBHOOK_URL}
        ]
    }
}

What will happen after running

  • Log file will be created each time script runs (in log/ directory)
Example log file:
[06:07:54] Waiting for internet access... (reference: https://google.com)
[06:07:54] Internet check failed: Cannot connect to host google.com:443 ssl:default [Could not contact DNS servers]
[06:07:59] Came online!
[06:08:02] example_bot#1234 is now running
[06:08:02] {'minecraft_server_url': 'example.com', 'minecraft_server_port': 25565, 'IDLE_CHECK_DELAY': 120, 'ACTIVE_CHECK_DELAY': 15, 'INACTIVITY_THRESHOLD_SECONDS': 300, 'online_check_reference': 'https://google.com', 'report_targets': [{'target_type': 'CHANNEL', 'target_id': 123456789123456789}]}
[06:08:02] 0 []
[06:08:50] 1 ['Notch']
[06:09:58] 2 ['Herobrine', 'Notch']
[06:11:50] 1 ['Herobrine']
[06:14:16] -1 []
[09:30:04] -2 []
  • Statistic file will be created each time script runs (in stats/ directory), it contains parts of the log, in pure form, good for statistic and analytic purposes
Example statistic file:
[06:08:02] 0 []
[06:08:50] 1 ['Notch']
[06:09:58] 2 ['Herobrine', 'Notch']
[06:11:50] 1 ['Herobrine']
[06:14:16] -1 []
[09:30:04] -2 []

Explanation:

// First number is number of players connected, then there is a list of all players
[06:08:02] 0 []                         // Server is empty
[06:08:50] 1 ['Notch']                  // There 1 player connected with nickname 'Notch'
[06:09:58] 2 ['Herobrine', 'Notch']
[06:11:50] 1 ['Herobrine']
[06:14:16] -1 []                        // Minecraft server is offline
[09:30:04] -2 []                        // We lost internet connection (aka we can't connect to our reference point set in `config.json` - in this case `https://google.com`)

Notes

  • Make sure that reference point in config.json has https:// or http:// prefix.
  • You can only use one discord bot.
  • You can send messages to multiple webhooks, channels or users.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages