diff --git a/ProxyBuilder/VMess.py b/ProxyBuilder/VMess.py new file mode 100644 index 0000000..ccd6100 --- /dev/null +++ b/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) diff --git a/ProxyBuilder/builder.py b/ProxyBuilder/builder.py index d03170d..9df411f 100644 --- a/ProxyBuilder/builder.py +++ b/ProxyBuilder/builder.py @@ -10,6 +10,7 @@ import subprocess from ProxyBuilder import Shadowsocks from ProxyBuilder import ShadowsocksR +from ProxyBuilder import VMess libcPaths = [ '/usr/lib64/libc.so.6', # CentOS @@ -100,6 +101,8 @@ def build(proxyInfo: dict, configDir: str, clientObj = Shadowsocks elif proxyInfo['type'] == 'ssr': # ShadowsocksR节点 clientObj = ShadowsocksR + elif proxyInfo['type'] == 'vmess': # VMess节点 + clientObj = VMess else: # 未知类型 return False, 'Unknown proxy type'