-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminecraft.py
More file actions
351 lines (296 loc) · 12.1 KB
/
minecraft.py
File metadata and controls
351 lines (296 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import json
import time
import signal
import random
import threading
import string
import requests
from queue import Queue
from typing import List, Optional
from urllib.parse import quote
from datetime import datetime
try:
import cloudscraper
except ImportError:
print("[-] Installing cloudscraper...")
os.system("pip install cloudscraper")
import cloudscraper
try:
from colorama import Fore, Style, init
init(autoreset=True)
except ImportError:
print("[-] Installing colorama...")
os.system("pip install colorama")
from colorama import Fore, Style, init
init(autoreset=True)
BANNER = f"""
{Fore.MAGENTA} __ __ ___ ____ ____ _ _ _____ ____ _ _ ____
{Fore.MAGENTA} | \/ |/ _ \___ \ / ___| | | | ____/ ___| | | | _ \
{Fore.MAGENTA} | |\/| | | | |__) | | | | | | _|| | | | | | |_) |
{Fore.MAGENTA} | | | | |_| / __/ |___| |__| | |__| |___| |_| | __/
{Fore.MAGENTA} |_| |_|\___/_____| \____|\____/|_____\____|\___/|_|
{Fore.CYAN} Minecraft Username Monitor v2025
{Fore.YELLOW} Multi-threaded • Proxies • Notifications
{Style.RESET_ALL}"""
# Configurable Client-ID (public, safe)
MOJANG_HEADERS = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
"Accept": "application/json"
}
class SentCache:
def __init__(self, path="sent_minecraft.json"):
self.path = path
self.lock = threading.Lock()
if os.path.exists(path):
try:
with open(path, "r", encoding="utf-8") as f:
self.sent = set(json.load(f))
except:
self.sent = set()
else:
self.sent = set()
def already_sent(self, username: str) -> bool:
with self.lock:
return username.lower() in self.sent
def add(self, username: str):
with self.lock:
self.sent.add(username.lower())
with open(self.path, "w", encoding="utf-8") as f:
json.dump(list(self.sent), f, indent=2)
class Counters:
def __init__(self):
self.lock = threading.Lock()
self.available = 0
self.taken = 0
self.errors = 0
self.ratelimited = 0
self.total_checked = 0
self.rps = 0
self.running = True
class Notifications:
def __init__(self, cfg: dict, sent_cache: SentCache):
n = cfg.get("enable_notifications", {})
self.discord = str(n.get("discord", "false")).lower() == "true"
self.telegram = str(n.get("telegram", "false")).lower() == "true"
self.webhook = cfg.get("discord_webhook", "")
self.bot_token = cfg.get("telegram_bot_token", "")
self.chat_id = cfg.get("telegram_chat_id", "")
self.sent_cache = sent_cache
self.scraper = cloudscraper.create_scraper()
def send(self, username: str):
if self.sent_cache.already_sent(username):
return
link = f"https://namemc.com/profile/{username}"
if self.discord and self.webhook:
payload = {
"embeds": [{
"title": f"Minecraft Username Dropping Soon!",
"description": f"**{username}** is available!\n[NameMC]({link})",
"color": 0x00ff00,
"timestamp": datetime.utcnow().isoformat(),
"footer": {"text": "Claim it before someone else!"}
}]
}
try:
self.scraper.post(self.webhook, json=payload, timeout=10)
except: pass
if self.telegram and self.bot_token and self.chat_id:
url = f"https://api.telegram.org/bot{self.bot_token}/sendMessage"
text = f"MINECRAFT USERNAME AVAILABLE!\n\nUsername: `{username}`\nLink: {link}"
try:
self.scraper.get(url, params={"chat_id": self.chat_id, "text": text, "parse_mode": "Markdown"}, timeout=10)
except: pass
self.sent_cache.add(username)
class DataLoader:
def __init__(self):
os.makedirs("data", exist_ok=True)
self.usernames_file = "data/usernames.txt"
self.proxies_file = "data/proxies.txt"
self.available_file = "data/available_minecraft.txt"
self.lock = threading.Lock()
for f in (self.usernames_file, self.proxies_file):
if not os.path.exists(f):
open(f, "w").close()
if not os.path.exists(self.available_file):
open(self.available_file, "w").close()
def load_usernames(self) -> List[str]:
try:
with open(self.usernames_file, "r", encoding="utf-8") as f:
return [line.strip() for line in f if line.strip() and self.validate(line.strip())]
except:
return []
def validate(self, username: str) -> bool:
return 3 <= len(username) <= 16 and all(c.isalnum() or c == '_' for c in username)
def remove_username(self, username: str):
with self.lock:
try:
lines = []
with open(self.usernames_file, "r", encoding="utf-8") as f:
lines = [l.strip() for l in f if l.strip() != username]
with open(self.usernames_file, "w", encoding="utf-8") as f:
f.write("\n".join(lines) + "\n")
except: pass
def save_available(self, username: str):
with self.lock:
with open(self.available_file, "a", encoding="utf-8") as f:
f.write(f"{username} - https://namemc.com/profile/{username}\n")
def load_proxies(self) -> List[Optional[str]]:
try:
with open(self.proxies_file, "r", encoding="utf-8") as f:
lines = [l.strip() for l in f if l.strip()]
proxies = []
for line in lines:
parts = line.split(":")
if len(parts) == 2:
proxies.append(f"http://{parts[0]}:{parts[1]}")
elif len(parts) == 4:
u, p = parts[2], quote(parts[3])
proxies.append(f"http://{u}:{p}@{parts[0]}:{parts[1]}")
return proxies or [None]
except:
return [None]
class MinecraftChecker(threading.Thread):
def __init__(self, queue: Queue, proxies, counters: Counters, notifier: Notifications, loader: DataLoader, debug: bool):
super().__init__(daemon=True)
self.q = queue
self.proxies = proxies
self.counters = counters
self.notifier = notifier
self.loader = loader
self.debug = debug
self.session = requests.Session()
self.session.headers.update(MOJANG_HEADERS)
def check(self, username: str) -> str:
username = username.strip().lower()
proxy = random.choice(self.proxies)
proxies = {"http": proxy, "https": proxy} if proxy else None
try:
url = f"https://api.mojang.com/users/profiles/minecraft/{username}"
r = self.session.get(url, proxies=proxies, timeout=10)
if r.status_code == 200:
return "taken"
elif r.status_code == 204 or r.status_code == 404:
# Double-check with NameMC or Ashcon to avoid false positives
if self.backup_check(username, proxies):
return "taken"
return "available"
elif r.status_code == 429:
time.sleep(2)
return "ratelimit"
else:
return "error"
except:
return "error"
def backup_check(self, username: str, proxies):
try:
r = requests.get(f"https://api.ashcon.app/mojang/v2/user/{username}", proxies=proxies, timeout=8)
return r.status_code == 200
except:
return False
def run(self):
while self.counters.running:
try:
username = self.q.get(timeout=1)
except:
continue
result = self.check(username)
self.loader.remove_username(username)
with self.counters.lock:
self.counters.total_checked += 1
if result == "available":
self.counters.available += 1
print(f"\r{Fore.GREEN}[+] AVAILABLE: {username} → https://namemc.com/profile/{username}", flush=True)
self.loader.save_available(username)
self.notifier.send(username)
elif result == "taken":
self.counters.taken += 1
elif result == "ratelimit":
self.counters.ratelimited += 1
self.q.put(username)
time.sleep(1)
else:
self.counters.errors += 1
self.q.task_done()
def print_status(counters: Counters):
while counters.running:
with counters.lock:
rps = counters.rps
msg = f"Checked: {counters.total_checked} | +Avail: {counters.available} | Taken: {counters.taken} | RL: {counters.ratelimited} | Err: {counters.errors} | R/s: {rps}"
print(f"\r{Fore.CYAN}[{msg.ljust(80)}]", end="", flush=True)
time.sleep(0.2)
def calc_rps(counters: Counters):
while counters.running:
prev = counters.total_checked
time.sleep(1)
with counters.lock:
counters.rps = counters.total_checked - prev
def stop(counters: Counters):
counters.running = False
print(f"\n{Fore.YELLOW}[!] Stopping threads...")
def main():
os.system('cls' if os.name == 'nt' else 'clear')
print(BANNER)
if not os.path.exists("config.json"):
print(f"{Fore.RED}[!] config.json not found! Creating default...")
default = {
"threads": 20,
"debug_mode": False,
"enable_notifications": {
"discord": False,
"telegram": False
},
"discord_webhook": "",
"telegram_bot_token": "",
"telegram_chat_id": ""
}
with open("config.json", "w") as f:
json.dump(default, f, indent=2)
print(f"{Fore.YELLOW}[!] Edit config.json and restart.")
return
with open("config.json", "r") as f:
cfg = json.load(f)
loader = DataLoader()
usernames = loader.load_usernames()
if not usernames:
print(f"{Fore.RED}No valid usernames in data/usernames.txt")
return
proxies = loader.load_proxies()
threads = max(1, int(cfg.get("threads", 20)))
debug = cfg.get("debug_mode", False)
print(f"{Fore.CYAN}[*] Loaded {len(usernames)} usernames")
print(f"{Fore.CYAN}[*] Using {len(proxies)} proxies | {threads} threads")
print(f"{Fore.YELLOW}[!] Press ENTER to start...")
input()
q = Queue()
for u in usernames:
q.put(u)
counters = Counters()
notifier = Notifications(cfg, SentCache())
workers = [MinecraftChecker(q, proxies, counters, notifier, loader, debug) for _ in range(threads)]
for w in workers:
w.start()
threading.Thread(target=calc_rps, args=(counters,), daemon=True).start()
threading.Thread(target=print_status, args=(counters,), daemon=True).start()
signal.signal(signal.SIGINT, lambda s, f: stop(counters))
try:
q.join()
time.sleep(2)
except:
pass
finally:
stop(counters)
for w in workers:
w.join(timeout=2)
print(f"\n\n{Fore.CYAN}Final Results:")
print(f"{Fore.GREEN} Available : {counters.available}")
print(f"{Fore.RED} Taken : {counters.taken}")
print(f"{Fore.YELLOW} Errors : {counters.errors}")
print(f"{Fore.WHITE} Total : {counters.total_checked}")
if counters.available > 0:
print(f"{Fore.GREEN}Check data/available_minecraft.txt")
if __name__ == "__main__":
main()