0
# V2ray Util
1
2
A comprehensive V2ray/Xray management utility that enables system administrators to configure and manage multi-user proxy servers with various transport protocols. It offers a wizard-style interface for adding, deleting, and modifying transmission protocols and provides both interactive menu-driven and command-line argument-based management interfaces for enterprise proxy infrastructure deployment and maintenance.
3
4
## Package Information
5
6
- **Package Name**: v2ray-util
7
- **Language**: Python
8
- **Installation**: `pip install v2ray-util`
9
- **Requirements**: Python 3.4+, root/sudo privileges
10
11
## Core Imports
12
13
```python
14
import v2ray_util
15
from v2ray_util.main import menu
16
```
17
18
For programmatic access to core components:
19
20
```python
21
from v2ray_util.util_core.v2ray import V2ray
22
from v2ray_util.util_core.utils import ColorStr, open_port, get_ip, clean_iptables
23
from v2ray_util.util_core.config import Config
24
from v2ray_util.util_core.profile import Profile
25
from v2ray_util.util_core.trans import _ # Translation function
26
from v2ray_util.util_core.writer import Writer, StreamWriter, GroupWriter, ClientWriter, GlobalWriter
27
```
28
29
## Basic Usage
30
31
### Command Line Interface
32
33
The package provides a console script for interactive management:
34
35
```bash
36
# Start the interactive menu
37
v2ray-util
38
39
# Direct commands
40
v2ray-util start # Start v2ray service
41
v2ray-util stop # Stop v2ray service
42
v2ray-util status # Check service status
43
v2ray-util info # Show configuration
44
v2ray-util add # Add new port/user interactively
45
v2ray-util add tcp # Add TCP protocol with random port
46
```
47
48
### Programmatic Usage
49
50
```python
51
from v2ray_util.util_core.v2ray import V2ray
52
from v2ray_util.util_core.config import Config
53
54
# Service management
55
V2ray.start()
56
V2ray.stop()
57
V2ray.restart()
58
V2ray.status()
59
60
# Configuration management
61
config = Config()
62
lang = config.get_data('lang')
63
config.set_data('lang', 'en')
64
65
# Get service information
66
V2ray.info()
67
V2ray.version()
68
```
69
70
## Architecture
71
72
The package is organized into several key modules:
73
74
- **v2ray_util.main**: Interactive menu system and command-line argument parsing
75
- **v2ray_util.util_core**: Core functionality including service management, utilities, and configuration
76
- **v2ray_util.config_modify**: Protocol and configuration modification capabilities
77
- **v2ray_util.global_setting**: Traffic statistics, iptables management, and global settings
78
79
The system supports both v2ray and xray management through runtime type detection, automatically adapting commands and configurations based on the detected or specified proxy type.
80
81
## Capabilities
82
83
### Core V2ray Management
84
85
Essential service management operations including starting, stopping, restarting services, version management, and configuration operations. Handles both Docker and systemd deployments.
86
87
```python { .api }
88
class V2ray:
89
@classmethod
90
def start(cls): ...
91
@classmethod
92
def stop(cls): ...
93
@classmethod
94
def restart(cls): ...
95
@staticmethod
96
def status(): ...
97
@staticmethod
98
def version(): ...
99
@staticmethod
100
def info(): ...
101
@staticmethod
102
def update(version=None): ...
103
@classmethod
104
def new(cls): ...
105
@classmethod
106
def remove(cls): ...
107
```
108
109
[Core V2ray Management](./core-management.md)
110
111
### User and Port Management
112
113
Multi-user and multi-port management capabilities for adding, deleting, and configuring users and port groups with various protocols.
114
115
```python { .api }
116
def new_port(new_stream=None): ...
117
def new_user(): ...
118
def del_port(): ...
119
def del_user(): ...
120
```
121
122
[User and Port Management](./user-port-management.md)
123
124
### Configuration Modification
125
126
Protocol configuration and modification capabilities including stream protocols, TLS settings, Shadowsocks, CDN configuration, and base configuration options.
127
128
```python { .api }
129
class StreamModifier:
130
def modify_stream(self, group, stream_type): ...
131
132
class TLSModifier:
133
def modify_tls(self, group): ...
134
135
def port(): ...
136
def new_uuid(): ...
137
def alterid(): ...
138
def tfo(): ...
139
```
140
141
[Configuration Modification](./config-modification.md)
142
143
### Traffic Statistics and Monitoring
144
145
Traffic monitoring through V2ray's official API and iptables, providing comprehensive traffic statistics and analysis capabilities.
146
147
```python { .api }
148
class StatsFactory:
149
def get_stats(self, group_list): ...
150
def get_inbound_stats(self, group_list): ...
151
152
def manage(stat_type=''): ...
153
def calcul_iptables_traffic(port, ipv6=False): ...
154
```
155
156
[Traffic Statistics](./traffic-statistics.md)
157
158
### Utilities and Global Settings
159
160
Utility functions for network operations, color output, validation, certificate generation, and global system settings.
161
162
```python { .api }
163
class ColorStr:
164
@classmethod
165
def red(cls, s): ...
166
@classmethod
167
def green(cls, s): ...
168
@classmethod
169
def yellow(cls, s): ...
170
171
def get_ip(): ...
172
def port_is_use(port): ...
173
def random_port(start_port, end_port): ...
174
def is_email(email): ...
175
def gen_cert(domain, cert_type, email=""): ...
176
```
177
178
[Utilities and Global Settings](./utilities-global-settings.md)
179
180
## Types
181
182
```python { .api }
183
class StreamType(Enum):
184
"""Transport protocol types"""
185
TCP = 'tcp'
186
TCP_HOST = 'tcp_host'
187
SOCKS = 'socks'
188
SS = 'ss'
189
MTPROTO = 'mtproto'
190
H2 = 'h2'
191
WS = 'ws'
192
GRPC = 'grpc'
193
QUIC = 'quic'
194
KCP = 'kcp'
195
KCP_UTP = 'utp'
196
KCP_SRTP = 'srtp'
197
KCP_DTLS = 'dtls'
198
KCP_WECHAT = 'wechat'
199
KCP_WG = 'wireguard'
200
VLESS_KCP = 'vless_kcp'
201
VLESS_UTP = 'vless_utp'
202
VLESS_SRTP = 'vless_srtp'
203
VLESS_DTLS = 'vless_dtls'
204
VLESS_WECHAT = 'vless_wechat'
205
VLESS_WG = 'vless_wireguard'
206
VLESS_TCP = 'vless_tcp'
207
VLESS_TLS = 'vless_tls'
208
VLESS_WS = 'vless_ws'
209
VLESS_GRPC = 'vless_grpc'
210
VLESS_REALITY = 'vless_reality'
211
TROJAN = 'trojan'
212
```
213
214
```python { .api }
215
class Config:
216
"""Configuration management"""
217
def get_data(self, key: str): ...
218
def set_data(self, key: str, value): ...
219
def get_path(self, key: str): ...
220
221
class Profile:
222
"""V2ray profile management"""
223
def read_json(self): ...
224
def parse_group(self, part_json, group_index, local_ip): ...
225
```
226
227
## Internationalization
228
229
```python { .api }
230
def _(text):
231
"""
232
Translation function for internationalization.
233
234
Parameters:
235
- text (str): Text to translate
236
237
Returns:
238
str: Translated text based on configured language (en/zh)
239
"""
240
```
241
242
## Command Line Reference
243
244
The package provides extensive command-line functionality:
245
246
- **Service Control**: `start`, `stop`, `restart`, `status`
247
- **Configuration**: `new`, `info`, `port`, `tls`, `tfo`, `stream`, `cdn`
248
- **User Management**: `add [protocol]`, `del`
249
- **Maintenance**: `update [version]`, `update.sh`, `clean`, `log [error|access]`, `rm`
250
- **Statistics**: `stats [type]`, `iptables [type]`