跳到正文

剪贴板

剪贴板 6j9e4knq

原文
剪贴板信息

剪贴板信息

收录
更新

Minecraft Server Seeker

C++
# 能不能rand到主要看rp

# ------ 配置 ------
# 设置任务数量
task_count = 100
# 设置线程间隔时间
thread_start_delay = 1  # 单位为秒
# ------ 配置 ------

from mcstatus import JavaServer
import random
import socket
import threading
import time
from queue import Queue

def get_minecraft_server_info(server_ip):
    try:
        # 创建MinecraftServer对象
        server = JavaServer.lookup(server_ip)

        # 获取服务器状态
        status = server.status()

        # 获取服务器信息
        version = status.version.name
        online_players = status.players.online
        max_players = status.players.max
        motd = status.description

        # 返回服务器信息
        return {
            "version": version,
            "online_players": online_players,
            "max_players": max_players,
            "motd": motd
        }
    except Exception as e:
        return {"error": str(e)}

def generate_random_ip():
    return ".".join(str(random.randint(0, 255)) for _ in range(4))

successful_ips = []
lock = threading.Lock()
task_queue = Queue()

def check_ip(worker_id):
    while not task_queue.empty():
        i = task_queue.get()
        ip = generate_random_ip()
        current_time = time.strftime("[%H:%M:%S]")
        print(f"{current_time} [MCSS worker #{worker_id}] 正在检查IP: {ip} ({i+1}/{task_count})")
        try:
            server_info = get_minecraft_server_info(ip)
            if "error" not in server_info:
                with lock:
                    successful_ips.append((ip, server_info))
                current_time = time.strftime("[%H:%M:%S]")
                print(f"{current_time} [MCSS worker #{worker_id}] 成功获取信息: {server_info}")
            else:
                current_time = time.strftime("[%H:%M:%S]")
                print(f"{current_time} [MCSS worker #{worker_id}] 获取信息失败: {server_info['error']}")
        except socket.herror:
            current_time = time.strftime("[%H:%M:%S]")
            print(f"{current_time} [MCSS worker #{worker_id}] IP {ip} 无法解析主机名,跳过。")
        finally:
            task_queue.task_done()
        time.sleep(thread_start_delay)

# 将任务放入队列
for i in range(task_count):
    task_queue.put(i)

threads = []

# 创建16个线程
for worker_id in range(16):
    thread = threading.Thread(target=check_ip, args=(worker_id,))
    threads.append(thread)
    thread.start()
    time.sleep(thread_start_delay)  # 使用变量设置线程开始时的间隔

# 等待所有任务完成
task_queue.join()

print("成功获取以下IP的信息:")
for ip, info in successful_ips:
    print(f"IP: {ip}, Info: {info}")