How gones75/nettracker-bot works
Project Type and Purpose
• This is a specialized Discord bot implemented in a single Python script (nettracker.py).
• Purpose: Provide network management and scanning tools (subnet scan, IP check, next-free IP lookup, IP details, network info) via Discord commands.
File Structure Analysis
• Top-level files only:
• .env.example – template for environment variables (Discord token, default network settings)
• nettracker.py – core application containing command handlers and scanning logic
• README.md – documentation and usage instructions
• .gitignore – standard ignore file
• No separate frontend/backend folders; it’s a single-process, event-driven application.
• Key libraries (from README): discord.py, python-dotenv, ipaddress. Scanning via ARP, ICMP ping, and TCP port checks.
Components
a. External Services and Data Sources
• Discord Gateway/API (external cloud service)
• Local network infrastructure (switches, routers, devices providing ARP tables, ICMP responses, open TCP ports)
b. Bot Application
• Environment/Configuration Loader (reads .env)
• Discord Client & Event Loop (discord.py event handlers)
• Command Dispatcher (parses !scan_subnet, !check_ip, etc.)
• Network Scanning Modules:
• ARP Scanner
• ICMP Pinger
• TCP Port Checker
• Response Formatter (builds messages, embeds results)
c. Communication Flows
• User → Discord API → Bot
• Bot → OS network stack → Network Devices → Bot
• Bot → Discord API → User (channel or DM)
Relationships and Interactions
• On startup: Configuration Loader reads environment variables from .env.
• The Discord Client connects to the Discord Gateway and listens for messages.
• When a user issues a command:
1. Event Loop receives message from Discord API.
2. Command Dispatcher routes to appropriate scanning routine.
3. Scanning Module(s) invoke the OS networking stack for ARP table lookup, ICMP echo, and/or TCP port attempts.
4. Scanning results are collected, formatted, and sent back via the Discord Client.
• Optionally: Command outputs are cleaned up or deleted after processing for privacy.
Architectural Patterns and Principles
• Event-driven architecture (Discord.py event loop).
• Modular separation between “command parsing” and “network scanning logic.”
• Single-process design with external dependencies handled via well-defined Python libraries.
• No persistent data store; ephemeral data flows from network scan to Discord message.
Detail and Clarity
• Block is clearly labeled with component name and key technology (e.g., “Discord Client (discord.py)”).
• .env file feeding into the Configuration Loader.
• OS network stack boundary between scanning modules and the external network.
• Retry logic or scanning fallbacks (ARP → Ping → TCP) to show the sequence of scan methods.