🤖 Telegram bot for managing Marzban nodes with advanced monitoring and security capabilities.
- Automatic setup of nodes on servers via SSH
- IP address validation with availability checking
- Progress indicators for long operations
- Management of existing nodes (view, delete)
- Node statistics by countries and statuses
- Real-time health monitoring of nodes
- Logging of all admin actions
- Rate limiting to prevent spam
- Input data validation
- Secure password handling
pip install -r requirements.txtCreate a .env file in the project root:
# Telegram Bot Configuration
TG_BOT_TOKEN=your_telegram_bot_token_here
TG_CHAT_ID=your_telegram_chat_id_here
# Marzban Configuration
MARZBAN_USERNAME=your_marzban_username
MARZBAN_PASSWORD=your_marzban_password
MARZBAN_URL=http://your_marzban_instance.com
# Marzban Node Certificate (base64 encoded)
MARZBAN_NODE_CERT=your_base64_encoded_certificate_herepython bot.py/start- Welcome and main menu🔧 Configure Node- Configure a new node📋 Nodes- Manage existing nodes📊 Statistics- Statistics and monitoring❓ Help- Detailed help
- Enter IP address - automatic validation and availability check
- Enter password - secure handling without logging
- Select ports - predefined or manual input
- Automatic setup - with progress indicators
- Add to Marzban - automatic node registration
- ✅ IP address validation using
ipaddress - ✅ SSH port (22) availability check
- ✅ Protection against localhost usage
- ✅ Port format validation
- 📝 All admin actions are logged to
bot.log - 🔒 Passwords are not saved in logs
- ⏰ Timestamps for all operations
- 🎯 Detailed error information
- 🌐 Node availability checking
- 📊 Statistics by countries and statuses
- 🔐 Access rights verification
- 🚫 Protection against unauthorized access
- 📋 Logging of unauthorized access attempts
marzban-node/
├── bot.py # Main bot file
├── marzban_node_api.py # API for Marzban integration
├── utils.py # Server utilities
├── requirements.txt # Python dependencies
├── .env # Environment variables
├── bot.log # Bot logs
└── README.md # Documentation
- Python 3.8+
- SSH access to servers
- Configured Marzban instance
- Telegram Bot Token
All actions are logged to bot.log in the format:
2024-01-01 12:00:00 - bot - INFO - ADMIN_ACTION: User 123456 - NODE_SETUP_STARTED - IP: 192.168.1.100, Ports: 8443:8880
The bot includes advanced error handling:
- Network errors when connecting to servers
- Marzban authentication errors
- Input data validation errors
- Timeouts for long operations
The bot provides detailed statistics:
- Total number of nodes
- Number of active/inactive nodes
- Distribution by geographic locations
- ✅ Enhanced IP address validation
- ✅ Action logging system
- ✅ Node health monitoring
- ✅ Statistics
- ✅ Progress indicators
- ✅ Enhanced error handling
If you encounter problems:
- Check logs in
bot.logfile - Ensure correct settings in
.env - Check server and Marzban API availability
- Ensure all dependencies are installed
MIT License