discord captchas suck. Gathering some data other ways.

This commit is contained in:
Purrfxct 2025-01-21 20:42:52 -05:00
parent fa5bd57675
commit ff0bde844a

170
newnew.py
View File

@ -4,7 +4,6 @@ import string
import time import time
import socket import socket
import threading import threading
import discord
import asyncio import asyncio
from datetime import datetime from datetime import datetime
import json import json
@ -14,25 +13,22 @@ import sys
# IRC connection settings # IRC connection settings
SERVER = "irc.supernets.org" SERVER = "irc.supernets.org"
PORT = 6667 PORT = 6667
CHANNEL = "#superbowl" CHANNEL = "#"
OLD_CHANNEL = "#blackhole" OUTPUT_CHANNEL = "#"
NICKNAME = "butts" OLD_CHANNEL = "#"
NICKSERV_PASSWORD = "butts" NICKNAME = ""
NICKSERV_PASSWORD = ""
# Discord Bot Token
DISCORD_BOT_TOKEN = "il1k3A1pH4B3tS0upZcUz1tT4ugHtM32r33dGuDS"
# Counters and metrics # Counters and metrics
valid_invite_count = 0 valid_invite_count = 0
scanned_invite_count = 0 scanned_invite_count = 0
valid_invites = []
error_count = 0 error_count = 0
rate_limited_count = 0 rate_limited_count = 0
scan_state_file = "scan_state.json" scan_state_file = "scan_state.json"
user_agents = [ user_agents = [
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Mobile Safari/537.36", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36",
"Mozilla/5.0 (Linux; Android 9; SM-A205U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.101 Mobile Safari/537.36" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36"
] ]
# Load scan state if exists # Load scan state if exists
@ -67,62 +63,7 @@ def generate_random_code():
characters = string.ascii_letters + string.digits characters = string.ascii_letters + string.digits
return ''.join(random.choice(characters) for _ in range(length)) return ''.join(random.choice(characters) for _ in range(length))
async def join_discord_and_list_members(client, invite_url, server_name, log_file, irc_socket): # Keep IRC connection alive by responding to PING messages
try:
invite = await client.fetch_invite(invite_url)
guild_id = invite.guild.id
guild = client.get_guild(guild_id)
if guild is None:
print(f"Invite URL {invite_url} is valid but does not reference a guild.")
irc_socket.sendall(f"PRIVMSG {CHANNEL} :Invite URL {invite_url} is valid but does not reference a guild.\r\n".encode("utf-8"))
return
members = await guild.fetch_members(limit=None).flatten()
member_count = len(members)
creation_date = guild.created_at.strftime("%Y-%m-%d %H:%M:%S")
print(f"Joined server: {guild.name} (Members: {member_count}, Created: {creation_date})")
irc_socket.sendall(f"PRIVMSG {CHANNEL} :Joining server: {server_name} ({invite_url}, Members: {member_count}, Created: {creation_date})\r\n".encode("utf-8"))
member_names = ", ".join(member.name for member in members)
log_file.write(f"{server_name}, {invite_url}, Members: {member_count}, Created: {creation_date}, {member_names}\n")
log_file.flush()
valid_invites.append((invite_url, datetime.now()))
except Exception as e:
global error_count
error_count += 1
print(f"Error joining server or fetching members: {e}")
irc_socket.sendall(f"PRIVMSG {CHANNEL} :Error joining server or fetching members: {e}\r\n".encode("utf-8"))
async def check_invite_http(url, log_file, irc_socket, client):
global valid_invite_count, scanned_invite_count, rate_limited_count
scanned_invite_count += 1
headers = {'User-Agent': get_random_user_agent()}
async with aiohttp.ClientSession() as session:
try:
async with session.get(url, headers=headers, timeout=10) as response:
if response.status == 429:
rate_limited_count += 1
print("Rate limit encountered. Slowing down.")
await asyncio.sleep(10)
return
if response.status == 200 and "Join the" in await response.text():
server_name = "Unknown Server"
if "<title>" in await response.text() and "</title>" in await response.text():
start = (await response.text()).find("<title>") + len("<title>")
end = (await response.text()).find("</title>")
server_name = (await response.text())[start:end].strip()
print(f"Valid invite found: {url}, {server_name}")
log_file.write(f"Valid invite: {url}, {server_name}\n")
log_file.flush()
valid_invite_count += 1
await join_discord_and_list_members(client, url, server_name, log_file, irc_socket)
else:
print(f"Invalid invite: {url}")
except Exception as e:
global error_count
error_count += 1
print(f"Error checking invite: {url} - {e}")
def keep_connection_alive(irc_socket): def keep_connection_alive(irc_socket):
try: try:
while True: while True:
@ -135,6 +76,7 @@ def keep_connection_alive(irc_socket):
except socket.error as e: except socket.error as e:
print(f"Connection error in keep_connection_alive: {e}") print(f"Connection error in keep_connection_alive: {e}")
# Handle initial IRC connection and commands
def handle_irc_connection(irc_socket): def handle_irc_connection(irc_socket):
irc_socket.sendall(f"NICK {NICKNAME}\r\n".encode("utf-8")) irc_socket.sendall(f"NICK {NICKNAME}\r\n".encode("utf-8"))
irc_socket.sendall(f"USER {NICKNAME} 0 * :{NICKNAME}\r\n".encode("utf-8")) irc_socket.sendall(f"USER {NICKNAME} 0 * :{NICKNAME}\r\n".encode("utf-8"))
@ -143,36 +85,87 @@ def handle_irc_connection(irc_socket):
time.sleep(5) time.sleep(5)
irc_socket.sendall(f"PRIVMSG NickServ :IDENTIFY {NICKSERV_PASSWORD}\r\n".encode("utf-8")) irc_socket.sendall(f"PRIVMSG NickServ :IDENTIFY {NICKSERV_PASSWORD}\r\n".encode("utf-8"))
print("Identified with NickServ.") print("Identified with NickServ.")
print("Waiting 5 seconds before leaving #blackhole...") print("Waiting 5 seconds before leaving old channel...")
time.sleep(5) time.sleep(5)
irc_socket.sendall(f"PART {OLD_CHANNEL}\r\n".encode("utf-8")) irc_socket.sendall(f"PART {OLD_CHANNEL}\r\n".encode("utf-8"))
print(f"Left channel {OLD_CHANNEL}") print(f"Left channel {OLD_CHANNEL}")
irc_socket.sendall(f"JOIN {CHANNEL}\r\n".encode("utf-8")) irc_socket.sendall(f"JOIN {CHANNEL}\r\n".encode("utf-8"))
print(f"Joined channel {CHANNEL}") print(f"Joined channel {CHANNEL}")
irc_socket.sendall(f"PRIVMSG {CHANNEL} :Starting invite scanner...\r\n".encode("utf-8")) irc_socket.sendall(f"PRIVMSG {CHANNEL} :Starting invite scanner...\r\n".encode("utf-8"))
irc_socket.sendall(f"JOIN {OUTPUT_CHANNEL}\r\n".encode("utf-8"))
print(f"Joined output channel {OUTPUT_CHANNEL}")
irc_socket.sendall(f"PRIVMSG {OUTPUT_CHANNEL} :Starting invite scanner...\r\n".encode("utf-8"))
async def check_invite_http(url, log_file, irc_socket):
global valid_invite_count, scanned_invite_count, rate_limited_count
scanned_invite_count += 1
headers = {'User-Agent': get_random_user_agent()}
api_url = url.replace("discord.com/invite", "discord.com/api/invites") + "?with_counts=true"
async with aiohttp.ClientSession() as session:
try:
async with session.get(api_url, headers=headers, timeout=10) as response:
if response.status == 429:
rate_limited_count += 1
print("Rate limit encountered. Slowing down.")
irc_socket.sendall(f"!!!RATE LIMIT HIT!!! - 5 MINUTE NAP.\r\n".encode("utf-8"))
await asyncio.sleep(300)
return
if response.status == 200:
data = await response.json()
guild_name = data.get("guild", {}).get("name", "Unknown Server")
guild_id = data.get("guild", {}).get("id", "Unknown")
description = data.get("guild", {}).get("description", "No description")
verification_level = data.get("guild", {}).get("verification_level", "Unknown")
nsfw_level = data.get("guild", {}).get("nsfw_level", "Unknown")
nsfw = data.get("guild", {}).get("nsfw", False)
premium_count = data.get("guild", {}).get("premium_subscription_count", 0)
presence_count = data.get("approximate_presence_count", 0)
member_count = data.get("approximate_member_count", 0)
log_entry = (f"Valid invite: {url}\n"
f"Guild Name: {guild_name}\n"
f"Guild ID: {guild_id}\n"
f"Description: {description}\n"
f"Verification Level: {verification_level}\n"
f"NSFW Level: {nsfw_level}\n"
f"NSFW: {nsfw}\n"
f"Premium Subscribers: {premium_count}\n"
f"Active Members: {presence_count}\n"
f"Total Members: {member_count}\n")
log_file.write(log_entry + "\n")
log_file.flush()
valid_invite_count += 1
irc_socket.sendall(f"PRIVMSG {OUTPUT_CHANNEL} :Valid invite found: {url} - Server name: {guild_name} - Description: {description} - Verification Level: {verification_level} - Members: {presence_count}/{member_count} - Premium subscribers: Premium Subscribers: {premium_count} - Verification Level: {verification_level} - NSFW: {nsfw} - NSFW Level: {nsfw_level}\r\n".encode("utf-8"))
else:
print(f"Invalid invite: {url}")
except Exception as e:
global error_count
error_count += 1
print(f"Error checking invite: {url} - {e}")
async def report_valid_invites(irc_socket): async def report_valid_invites(irc_socket):
global valid_invite_count, scanned_invite_count, error_count, rate_limited_count global valid_invite_count, scanned_invite_count, error_count, rate_limited_count
while True: while True:
await asyncio.sleep(600) # 10 minutes await asyncio.sleep(600) # 10 minutes
irc_socket.sendall(f"PRIVMSG {CHANNEL} :Valid invites found: {valid_invite_count}, Links scanned: {scanned_invite_count}, Errors: {error_count}, Rate limits hit: {rate_limited_count}\r\n".encode("utf-8")) irc_socket.sendall(f"PRIVMSG {CHANNEL} :Valid invites found: {valid_invite_count}, Links scanned: {scanned_invite_count}, Errors: {error_count}, Rate limits hit: {rate_limited_count}\r\n".encode("utf-8"))
irc_socket.sendall(f"PRIVMSG {OUTPUT_CHANNEL} :Valid invites found: {valid_invite_count}, Links scanned: {scanned_invite_count}, Errors: {error_count}, Rate limits hit: {rate_limited_count}\r\n".encode("utf-8"))
async def shutdown_handler(irc_socket, client): async def shutdown_handler(irc_socket):
print("Shutting down gracefully...") print("Shutting down gracefully...")
irc_socket.sendall(f"PRIVMSG {CHANNEL} :Stopping invite scanner.\r\n".encode("utf-8")) irc_socket.sendall(f"PRIVMSG {CHANNEL} :Stopping invite scanner.\r\n".encode("utf-8"))
irc_socket.sendall(f"PRIVMSG {OUTPUT_CHANNEL} :Stopping invite scanner.\r\n".encode("utf-8"))
irc_socket.close() irc_socket.close()
await client.close()
save_scan_state() save_scan_state()
sys.exit() sys.exit()
async def run_scanner(log_file, irc_socket, client): async def run_scanner(log_file, irc_socket):
global shutdown_event
try: try:
while not shutdown_event.is_set(): while True:
random_code = generate_random_code() random_code = generate_random_code()
invite_url = f"https://discord.com/invite/{random_code}" invite_url = f"https://discord.com/invite/{random_code}"
await check_invite_http(invite_url, log_file, irc_socket, client) await check_invite_http(invite_url, log_file, irc_socket)
await asyncio.sleep(random.uniform(0.5, 1)) await asyncio.sleep(random.uniform(5, 10))
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
@ -182,30 +175,11 @@ async def main():
irc_socket = socket.create_connection((SERVER, PORT)) irc_socket = socket.create_connection((SERVER, PORT))
handle_irc_connection(irc_socket) handle_irc_connection(irc_socket)
intents = discord.Intents.all() signal.signal(signal.SIGINT, lambda *args: sys.exit())
client = discord.Client(intents=intents) signal.signal(signal.SIGTERM, lambda *args: sys.exit())
@client.event
async def on_ready():
print(f'Logged in as {client.user}')
global shutdown_event
shutdown_event = threading.Event() # Use threading.Event instead of asyncio.Event
def on_signal(signum, frame):
shutdown_event.set() # Set the shutdown_event to signal termination
signal.signal(signal.SIGINT, on_signal)
signal.signal(signal.SIGTERM, on_signal)
asyncio.create_task(report_valid_invites(irc_socket)) asyncio.create_task(report_valid_invites(irc_socket))
scanner_task = asyncio.create_task(run_scanner(log_file, irc_socket, client)) await run_scanner(log_file, irc_socket)
try:
await client.start(DISCORD_BOT_TOKEN) # Properly start the Discord client
await scanner_task
finally:
await shutdown_handler(irc_socket, client)
if __name__ == "__main__": if __name__ == "__main__":
load_scan_state() load_scan_state()