CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-v2ray-util

V2ray/Xray multi-user management utility for configuring proxy servers with various transport protocols

Overview
Eval results
Files

user-port-management.mddocs/

User and Port Management

Multi-user and multi-port management capabilities for V2ray/Xray proxy servers. Enables adding, deleting, and configuring users and port groups with various protocols including VMess, VLESS, Trojan, Shadowsocks, Socks5, and MTProto.

Capabilities

Port Group Management

Add and remove port groups with different protocols and configurations.

def new_port(new_stream=None):
    """
    Add a new port group with specified or interactive protocol selection.
    
    Parameters:
    - new_stream (str, optional): Protocol type to add automatically.
                                 Supported: 'tcp', 'tcp_http', 'ws', 'h2', 
                                 'mkcp', 'utp', 'srtp', 'wechat-video', 
                                 'dtls', 'wireguard', 'quic', 'socks', 
                                 'mtproto', 'ss', 'vless_tcp', 'vless_tls',
                                 'vless_ws', 'vless_reality', 'trojan'
    
    If new_stream is None, opens interactive menu for protocol selection.
    Generates random port and creates configuration for selected protocol.
    Automatically opens firewall ports and restarts service.
    """

def del_port():
    """
    Delete an existing port group interactively.
    
    Displays list of configured port groups and allows selection
    for deletion. Removes all associated users and configurations.
    Updates firewall rules and restarts service.
    """

User Management

Add and remove individual users within existing port groups.

def new_user():
    """
    Add a new user to an existing port group.
    
    Interactive process to:
    1. Select target port group
    2. Configure user-specific settings (UUID, email, etc.)
    3. Apply changes and restart service
    
    Supports all protocol types with appropriate user configurations.
    """

def del_user():
    """
    Delete an existing user from a port group.
    
    Interactive selection from configured users across all port groups.
    Preserves port group configuration while removing specific user.
    """

User and Group Classes

Base User Class

class User:
    """Base class for all user types"""
    def __init__(self, port, uuid, email, alter_id=0):
        """
        Initialize user with basic parameters.
        
        Parameters:
        - port (int): Port number for the user
        - uuid (str): User UUID
        - email (str): User email identifier
        - alter_id (int): VMess AlterID (default: 0)
        """
    
    def user_info(self):
        """Return user configuration information"""
    
    def protocol(self):
        """Return protocol type string"""

Protocol-Specific User Classes

class Vmess(User):
    """VMess protocol user management"""
    def __init__(self, port, uuid, alter_id, email, path=None):
        """
        VMess user with optional WebSocket path.
        
        Parameters:
        - path (str, optional): WebSocket path for WS transport
        """
    
    def link_vmess(self):
        """Generate VMess connection string"""

class Vless(User):
    """VLESS protocol user management"""
    def __init__(self, port, uuid, email, flow=None):
        """
        VLESS user with optional XTLS flow.
        
        Parameters:
        - flow (str, optional): XTLS flow type
        """
    
    def link_vless(self):
        """Generate VLESS connection string"""

class Trojan(User):
    """Trojan protocol user management"""
    def __init__(self, port, password, email):
        """
        Trojan user with password authentication.
        
        Parameters:
        - password (str): Trojan password
        """
    
    def link_trojan(self):
        """Generate Trojan connection string"""

class SS(User):
    """Shadowsocks user management"""
    def __init__(self, port, password, method, email):
        """
        Shadowsocks user configuration.
        
        Parameters:
        - password (str): SS password
        - method (str): Encryption method
        """

class Socks(User):
    """Socks5 proxy user management"""
    def __init__(self, port, username, password, email):
        """
        Socks5 user with authentication.
        
        Parameters:
        - username (str): Socks5 username
        - password (str): Socks5 password
        """

class Mtproto(User):
    """MTProto (Telegram) user management"""
    def __init__(self, port, secret, email):
        """
        MTProto user for Telegram proxy.
        
        Parameters:
        - secret (str): MTProto secret
        """
    
    def link_mtproto(self):
        """Generate MTProto connection string"""

Group Management

class Group:
    """Port group management with multiple users"""
    def __init__(self, port, stream_type):
        """
        Initialize port group.
        
        Parameters:
        - port (int): Group port number
        - stream_type (str): Transport protocol type
        """
    
    def add_user(self, user):
        """Add user to the group"""
    
    def del_user(self, user_index):
        """Remove user from the group"""
    
    def group_info(self):
        """Display group configuration and user list"""

Dynamic Port Management

class Dyport:
    """Dynamic port range management"""
    def __init__(self, start_port, end_port):
        """
        Configure dynamic port range.
        
        Parameters:
        - start_port (int): Range start port
        - end_port (int): Range end port
        """

Usage Examples

Adding Port Groups

from v2ray_util.config_modify.multiple import new_port, new_user

# Interactive port addition
new_port()

# Add specific protocol with random port
new_port('tcp')        # TCP protocol
new_port('ws')         # WebSocket protocol
new_port('mkcp')       # mKCP protocol
new_port('trojan')     # Trojan protocol
new_port('vless_tcp')  # VLESS over TCP
new_port('ss')         # Shadowsocks

User Management

# Add new user to existing port group
new_user()

# Delete existing user
from v2ray_util.config_modify.multiple import del_user, del_port

del_user()  # Remove specific user
del_port()  # Remove entire port group

Programmatic Group Management

from v2ray_util.util_core.group import Group, Vmess

# Create port group
group = Group(8080, 'tcp')

# Create and add VMess user
user = Vmess(8080, 'uuid-string', 2, 'user@example.com')
group.add_user(user)

# Display group information
group.group_info()

Supported Protocols

Transport Protocols

  • TCP: Standard TCP transport
  • TCP_HTTP: TCP with HTTP header masquerading
  • WebSocket (WS): WebSocket transport with custom paths
  • HTTP/2 (H2): HTTP/2 over TLS (requires domain)
  • mKCP: UDP-based reliable transport with various masquerading:
    • UTP: BitTorrent uTP masquerading
    • SRTP: FaceTime call masquerading
    • wechat-video: WeChat video call masquerading
    • DTLS: DTLS 1.2 masquerading
    • wireguard: WireGuard masquerading
  • QUIC: Quick UDP Internet Connections

Proxy Protocols

  • VMess: V2ray's proprietary protocol
  • VLESS: Lightweight version of VMess
  • Trojan: Trojan proxy protocol
  • Shadowsocks: Popular SOCKS5-based proxy
  • Socks5: Standard SOCKS5 proxy
  • MTProto: Telegram proxy protocol

Interactive Features

All user and port management functions provide:

  • Interactive protocol selection menus
  • Automatic port generation and conflict detection
  • Real-time configuration validation
  • Automatic firewall rule management
  • Service restart with status verification
  • Connection string generation for client configuration

Install with Tessl CLI

npx tessl i tessl/pypi-v2ray-util

docs

config-modification.md

core-management.md

index.md

traffic-statistics.md

user-port-management.md

utilities-global-settings.md

tile.json