Browse Source

feat: demo of VMess Builder

master
Dnomd343 3 years ago
parent
commit
4b9aefe23a
  1. 89
      ProxyBuilder/VMess.py
  2. 3
      ProxyBuilder/builder.py

89
ProxyBuilder/VMess.py

@ -0,0 +1,89 @@
#!/usr/bin/python
# -*- coding:utf-8 -*-
import json
logLevel = 'warning'
def __baseConfig(socksPort: int, outboundObject: dict) -> dict:
return {
'log': {
'loglevel': logLevel
},
'inbounds': [
{
'port': socksPort,
'listen': '127.0.0.1',
'protocol': 'socks',
'settings': {
'udp': True,
'auth': 'noauth'
}
}
],
'outbounds': [
outboundObject
]
}
def __vmessConfig(proxyInfo: dict) -> dict:
streamObject = {}
return {
'protocol': 'vmess',
'settings': {
'vnext': [
{
'address': proxyInfo['server'],
'port': proxyInfo['port'],
'users': [
{
'id': proxyInfo['id'],
'alterId': proxyInfo['aid'],
'security': proxyInfo['method']
}
]
}
]
},
'streamSettings': streamObject
}
def load(proxyInfo: dict, socksPort: int, configFile: str) -> tuple[list or None, str or None, dict or None]:
"""
VMess配置载入
proxyInfo: 节点信息
socksPort: 本地通讯端口
configFile: 配置文件路径
节点有误:
return None, None, None
载入成功:
return startCommand, fileContent, envVar
"""
# if not __vmessFormatCheck(proxyInfo): # 参数有误
# return None, None, None
config = __baseConfig(socksPort, __vmessConfig(proxyInfo))
return ['v2ray', '-c', configFile], json.dumps(config), {}
info = {
'server': '1.1.1.1',
'port': 12345,
'method': 'aes-128-gcm',
'id': 'eb6273f1-a98f-59f6-ba52-945f11dee100',
'aid': 64,
'stream': {
'type': 'tcp',
'obfs': None,
'secure': {
'sni': '',
'alpn': 'h2,http/1.1',
'verify': True
}
}
}
ret = load(info, 1080, '/tmp/ProxyC/test.json')
print(ret)

3
ProxyBuilder/builder.py

@ -10,6 +10,7 @@ import subprocess
from ProxyBuilder import Shadowsocks from ProxyBuilder import Shadowsocks
from ProxyBuilder import ShadowsocksR from ProxyBuilder import ShadowsocksR
from ProxyBuilder import VMess
libcPaths = [ libcPaths = [
'/usr/lib64/libc.so.6', # CentOS '/usr/lib64/libc.so.6', # CentOS
@ -100,6 +101,8 @@ def build(proxyInfo: dict, configDir: str,
clientObj = Shadowsocks clientObj = Shadowsocks
elif proxyInfo['type'] == 'ssr': # ShadowsocksR节点 elif proxyInfo['type'] == 'ssr': # ShadowsocksR节点
clientObj = ShadowsocksR clientObj = ShadowsocksR
elif proxyInfo['type'] == 'vmess': # VMess节点
clientObj = VMess
else: # 未知类型 else: # 未知类型
return False, 'Unknown proxy type' return False, 'Unknown proxy type'

Loading…
Cancel
Save