V2ray/Xray multi-user management utility for configuring proxy servers with various transport protocols
Comprehensive utility functions and global system settings for V2ray/Xray management. Provides network operations, validation functions, color output, certificate generation, BitTorrent blocking, scheduled updates, and system configuration management.
Terminal color formatting for enhanced user interface and status indication.
class ColorStr:
"""Terminal color string utilities for formatted output"""
RED = '\033[31m'
GREEN = '\033[32m'
YELLOW = '\033[33m'
BLUE = '\033[34m'
FUCHSIA = '\033[35m'
CYAN = '\033[36m'
WHITE = '\033[37m'
RESET = '\033[0m'
@classmethod
def red(cls, s):
"""
Apply red color to string.
Parameters:
- s (str): String to colorize
Returns:
str: Red-colored string with reset
"""
@classmethod
def green(cls, s):
"""Apply green color (success messages)"""
@classmethod
def yellow(cls, s):
"""Apply yellow color (warning messages)"""
@classmethod
def blue(cls, s):
"""Apply blue color (information messages)"""
@classmethod
def cyan(cls, s):
"""Apply cyan color (headers and titles)"""
@classmethod
def fuchsia(cls, s):
"""Apply fuchsia/magenta color"""Network-related utility functions for IP detection, port management, and connectivity.
def get_ip():
"""
Get server's public IP address.
Returns:
str: Public IPv4 address of the server
Uses multiple IP detection services for reliability.
"""
def port_is_use(port):
"""
Check if a port is currently in use.
Parameters:
- port (int): Port number to check
Returns:
bool: True if port is in use, False if available
"""
def random_port(start_port, end_port):
"""
Generate random port within specified range.
Parameters:
- start_port (int): Range start (inclusive)
- end_port (int): Range end (inclusive)
Returns:
int: Random port number within range
"""
def all_port():
"""
Get list of all configured proxy ports.
Returns:
list: All ports currently configured for V2ray/Xray
"""
def open_port(openport=-1):
"""
Open port(s) in system firewall.
Parameters:
- openport (int, optional): Specific port to open.
If -1, opens all configured ports.
Handles both iptables and ufw firewall management.
"""Input validation and data verification utilities.
def is_email(email):
"""
Validate email address format.
Parameters:
- email (str): Email address to validate
Returns:
bool: True if valid email format
"""
def is_ipv4(ip):
"""
Validate IPv4 address format.
Parameters:
- ip (str): IP address string
Returns:
bool: True if valid IPv4 address
"""
def is_ipv6(ip):
"""
Validate IPv6 address format.
Parameters:
- ip (str): IPv6 address string
Returns:
bool: True if valid IPv6 address
"""
def check_ip(ip):
"""
Check if IP address is valid (IPv4 or IPv6).
Parameters:
- ip (str): IP address to check
Returns:
bool: True if valid IP address
"""Certificate generation and cryptographic key management.
def gen_cert(domain, cert_type, email=""):
"""
Generate SSL certificates for TLS configuration.
Parameters:
- domain (str): Domain name for certificate
- cert_type (str): Certificate type ('self', 'letsencrypt', 'custom')
- email (str, optional): Email for Let's Encrypt registration
Returns:
tuple: (certificate_path, private_key_path)
Supports self-signed certificates and Let's Encrypt ACME.
"""
def x25519_key(private_key=None):
"""
Generate X25519 key pair for VLESS Reality.
Parameters:
- private_key (str, optional): Existing private key to derive public key
Returns:
tuple: (private_key, public_key) in base64 format
"""Interactive input and user interface helper functions.
def loop_input_choice_number(input_tip, length):
"""
Interactive number choice input with validation.
Parameters:
- input_tip (str): Prompt message for user
- length (int): Maximum valid choice number
Returns:
int: User's validated choice (1 to length)
Loops until valid input is provided.
"""
def readchar(prompt=""):
"""
Read single character input without Enter.
Parameters:
- prompt (str, optional): Prompt message
Returns:
str: Single character pressed by user
"""
def random_email():
"""
Generate random email address for testing.
Returns:
str: Random email in format user@domain.com
"""Data conversion and formatting utilities.
def bytes_2_human_readable(number_of_bytes, precision=1):
"""
Convert bytes to human-readable format.
Parameters:
- number_of_bytes (int): Raw byte count
- precision (int): Decimal places for display
Returns:
str: Formatted string (e.g., "1.5 GB", "256.7 MB", "42.3 KB")
Supports bytes, KB, MB, GB, TB, PB units.
"""class Config:
"""Global configuration management"""
def __init__(self):
"""Initialize configuration manager"""
def get_data(self, key):
"""
Retrieve configuration value.
Parameters:
- key (str): Configuration key
Returns:
Any: Configuration value for the key
"""
def set_data(self, key, value):
"""
Set configuration value.
Parameters:
- key (str): Configuration key
- value (Any): Value to store
"""
def get_path(self, key):
"""
Get configuration file path.
Parameters:
- key (str): Path key ('config_path', etc.)
Returns:
str: File path for the specified key
"""def manage():
"""
Manage BitTorrent traffic blocking.
Interactive menu for:
- Enable/disable BT blocking via iptables
- Configure DPI-based protocol detection
- Whitelist/blacklist specific BT clients
"""def restartCron():
"""
Restart cron service for scheduled tasks.
Ensures cron daemon is running for automatic updates.
"""
def planUpdate():
"""
Configure scheduled V2ray updates.
Interactive setup for:
- Update frequency (daily, weekly, monthly)
- Update time preferences
- Automatic restart options
- Backup before update
"""
def manage():
"""
Manage scheduled update system.
Provides interface for configuring, enabling,
disabling, and monitoring automatic updates.
"""def iptables_open(iptable_way, port):
"""
Open port using specific iptables method.
Parameters:
- iptable_way (str): Firewall method ('iptables', 'ufw', 'firewalld')
- port (int): Port number to open
Handles different Linux firewall systems.
"""
def clean_iptables(port):
"""
Clean iptables rules for specified port.
Parameters:
- port (int): Port number to clean rules for
Removes all iptables rules related to the specified port,
including traffic accounting and forwarding rules.
"""class StreamType(Enum):
"""Transport protocol enumeration"""
TCP = 'tcp'
TCP_HTTP = 'tcp_http'
WS = 'ws'
H2 = 'h2'
MKCP = 'mkcp'
QUIC = 'quic'
SOCKS = 'socks'
MTPROTO = 'mtproto'
SHADOWSOCKS = 'shadowsocks'
VLESS_TCP = 'vless_tcp'
VLESS_TLS = 'vless_tls'
VLESS_WS = 'vless_ws'
VLESS_REALITY = 'vless_reality'
TROJAN = 'trojan'def header_type_list():
"""
Get list of available mKCP header masquerading types.
Returns:
list: ['none', 'srtp', 'utp', 'wechat-video', 'dtls', 'wireguard']
"""
def ss_method():
"""
Get list of supported Shadowsocks encryption methods.
Returns:
list: Available encryption methods for Shadowsocks
"""
def xtls_flow():
"""
Get list of supported XTLS flow control methods.
Returns:
list: Available XTLS flow types for VLESS
"""from v2ray_util.util_core.utils import ColorStr
print(ColorStr.green("Service started successfully"))
print(ColorStr.red("Error: Configuration invalid"))
print(ColorStr.yellow("Warning: Port already in use"))
print(ColorStr.cyan("V2ray Manager v3.11.4"))from v2ray_util.util_core.utils import get_ip, port_is_use, random_port, open_port
# Get server IP
server_ip = get_ip()
print(f"Server IP: {server_ip}")
# Check port availability
if not port_is_use(8080):
print("Port 8080 is available")
# Generate random port
port = random_port(10000, 65535)
print(f"Random port: {port}")
# Open ports in firewall
open_port(8080) # Open specific port
open_port() # Open all configured portsfrom v2ray_util.util_core.utils import is_email, is_ipv4, check_ip
# Validate email
if is_email("user@example.com"):
print("Valid email")
# Validate IP addresses
if is_ipv4("192.168.1.1"):
print("Valid IPv4")
if check_ip("2001:db8::1"):
print("Valid IP address")from v2ray_util.util_core.utils import gen_cert, x25519_key
# Generate self-signed certificate
cert_path, key_path = gen_cert("example.com", "self")
# Generate Let's Encrypt certificate
cert_path, key_path = gen_cert("example.com", "letsencrypt", "admin@example.com")
# Generate X25519 keys
private_key, public_key = x25519_key()from v2ray_util.util_core.config import Config
config = Config()
# Get current language
lang = config.get_data('lang')
# Set language to English
config.set_data('lang', 'en')from v2ray_util.global_setting import ban_bt, update_timer
# Manage BitTorrent blocking
ban_bt.manage()
# Configure scheduled updates
update_timer.manage()Utility functions handle common error conditions:
All functions provide appropriate error messages and fallback mechanisms to maintain system stability.
Install with Tessl CLI
npx tessl i tessl/pypi-v2ray-util