|
@ -5,6 +5,40 @@ import json |
|
|
|
|
|
|
|
|
logLevel = 'warning' |
|
|
logLevel = 'warning' |
|
|
|
|
|
|
|
|
|
|
|
httpHeader = { |
|
|
|
|
|
'type': 'http', |
|
|
|
|
|
'request': { |
|
|
|
|
|
'version': '1.1', |
|
|
|
|
|
'method': 'GET', |
|
|
|
|
|
'path': [], |
|
|
|
|
|
'headers': { |
|
|
|
|
|
'Host': [], |
|
|
|
|
|
'User-Agent': [ |
|
|
|
|
|
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36', |
|
|
|
|
|
'Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_2 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/53.0.2785.109 Mobile/14A456 Safari/601.1.46' |
|
|
|
|
|
], |
|
|
|
|
|
'Accept-Encoding': [ |
|
|
|
|
|
'gzip, deflate' |
|
|
|
|
|
], |
|
|
|
|
|
'Connection': [ |
|
|
|
|
|
'keep-alive' |
|
|
|
|
|
], |
|
|
|
|
|
'Pragma': 'no-cache' |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
kcpSettings = { |
|
|
|
|
|
'mtu': 1350, |
|
|
|
|
|
'tti': 50, |
|
|
|
|
|
'uplinkCapacity': 12, |
|
|
|
|
|
'downlinkCapacity': 100, |
|
|
|
|
|
'congestion': False, |
|
|
|
|
|
'readBufferSize': 2, |
|
|
|
|
|
'writeBufferSize': 2, |
|
|
|
|
|
'header': {} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
def __baseConfig(socksPort: int, outboundObject: dict) -> dict: # v2ray配置生成 |
|
|
def __baseConfig(socksPort: int, outboundObject: dict) -> dict: # v2ray配置生成 |
|
|
return { |
|
|
return { |
|
|
'log': { |
|
|
'log': { |
|
@ -29,24 +63,33 @@ def __baseConfig(socksPort: int, outboundObject: dict) -> dict: # v2ray配置生 |
|
|
def __secureConfig(secureInfo: dict or None) -> dict: # TLS加密传输配置 |
|
|
def __secureConfig(secureInfo: dict or None) -> dict: # TLS加密传输配置 |
|
|
if secureInfo is None: |
|
|
if secureInfo is None: |
|
|
return {} |
|
|
return {} |
|
|
|
|
|
tlsObject = { |
|
|
|
|
|
'allowInsecure': not secureInfo['verify'], |
|
|
|
|
|
'alpn': secureInfo['alpn'].split(',') |
|
|
|
|
|
} |
|
|
|
|
|
if secureInfo['sni'] != '': |
|
|
|
|
|
tlsObject['serverName'] = secureInfo['sni'] |
|
|
return { |
|
|
return { |
|
|
'security': 'tls', |
|
|
'security': 'tls', |
|
|
'tlsSettings': { |
|
|
'tlsSettings': tlsObject |
|
|
'allowInsecure': not secureInfo['verify'] |
|
|
|
|
|
# sni |
|
|
|
|
|
# alpn |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def __tcpConfig(streamInfo: dict) -> dict: # TCP传输方式配置 |
|
|
def __tcpConfig(streamInfo: dict) -> dict: # TCP传输方式配置 |
|
|
tcpObject = {} |
|
|
tcpObject = {} |
|
|
|
|
|
if streamInfo['obfs'] is not None: |
|
|
|
|
|
httpHeader['request']['path'].append(streamInfo['obfs']['path']) |
|
|
|
|
|
httpHeader['request']['headers']['Host'] = streamInfo['obfs']['host'].split(',') |
|
|
|
|
|
tcpObject['header'] = httpHeader |
|
|
return {**{ |
|
|
return {**{ |
|
|
'network': 'tcp', |
|
|
'network': 'tcp', |
|
|
'tcpSettings': tcpObject |
|
|
'tcpSettings': tcpObject |
|
|
}, **__secureConfig(streamInfo['secure'])} |
|
|
}, **__secureConfig(streamInfo['secure'])} |
|
|
|
|
|
|
|
|
def __kcpConfig(streamInfo: dict) -> dict: # mKCP传输方式配置 |
|
|
def __kcpConfig(streamInfo: dict) -> dict: # mKCP传输方式配置 |
|
|
kcpObject = {} |
|
|
kcpObject = kcpSettings |
|
|
|
|
|
kcpObject['header']['type'] = streamInfo['obfs'] |
|
|
|
|
|
if streamInfo['seed'] is not None: |
|
|
|
|
|
kcpObject['seed'] = streamInfo['seed'] |
|
|
return {**{ |
|
|
return {**{ |
|
|
'network': 'kcp', |
|
|
'network': 'kcp', |
|
|
'kcpSettings': kcpObject |
|
|
'kcpSettings': kcpObject |
|
@ -54,30 +97,48 @@ def __kcpConfig(streamInfo: dict) -> dict: # mKCP传输方式配置 |
|
|
|
|
|
|
|
|
def __wsConfig(streamInfo: dict) -> dict: # WebSocket传输方式配置 |
|
|
def __wsConfig(streamInfo: dict) -> dict: # WebSocket传输方式配置 |
|
|
wsObject = {} |
|
|
wsObject = {} |
|
|
|
|
|
if streamInfo['path'] != '': |
|
|
|
|
|
wsObject['path'] = streamInfo['path'] |
|
|
|
|
|
if streamInfo['host'] != '': |
|
|
|
|
|
wsObject['headers'] = {} |
|
|
|
|
|
wsObject['headers']['Host'] = streamInfo['host'] |
|
|
|
|
|
if streamInfo['ed'] is not None: |
|
|
|
|
|
wsObject['maxEarlyData'] = streamInfo['ed'] |
|
|
|
|
|
wsObject['earlyDataHeaderName'] = 'Sec-WebSocket-Protocol' |
|
|
return {**{ |
|
|
return {**{ |
|
|
'network': 'ws', |
|
|
'network': 'ws', |
|
|
'wsSettings': wsObject |
|
|
'wsSettings': wsObject |
|
|
}, **__secureConfig(streamInfo['secure'])} |
|
|
}, **__secureConfig(streamInfo['secure'])} |
|
|
|
|
|
|
|
|
def __h2Config(streamInfo: dict) -> dict: # HTTP/2传输方式配置 |
|
|
def __h2Config(streamInfo: dict) -> dict: # HTTP/2传输方式配置 |
|
|
h2Object = {} |
|
|
h2Object = { |
|
|
|
|
|
'path': streamInfo['path'] |
|
|
|
|
|
} |
|
|
|
|
|
if streamInfo['host'] != '': |
|
|
|
|
|
h2Object['host'] = streamInfo['host'].split(',') |
|
|
return {**{ |
|
|
return {**{ |
|
|
'network': 'h2', |
|
|
'network': 'h2', |
|
|
'httpSettings': h2Object |
|
|
'httpSettings': h2Object |
|
|
}, **__secureConfig(streamInfo['secure'])} |
|
|
}, **__secureConfig(streamInfo['secure'])} |
|
|
|
|
|
|
|
|
def __quicConfig(streamInfo: dict) -> dict: # QUIC传输方式配置 |
|
|
def __quicConfig(streamInfo: dict) -> dict: # QUIC传输方式配置 |
|
|
quicObject = {} |
|
|
|
|
|
return {**{ |
|
|
return {**{ |
|
|
'network': 'quic', |
|
|
'network': 'quic', |
|
|
'quicSettings': quicObject |
|
|
'quicSettings': { |
|
|
|
|
|
'security': streamInfo['method'], |
|
|
|
|
|
'key': streamInfo['passwd'], |
|
|
|
|
|
'header': { |
|
|
|
|
|
'type': streamInfo['obfs'] |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
}, **__secureConfig(streamInfo['secure'])} |
|
|
}, **__secureConfig(streamInfo['secure'])} |
|
|
|
|
|
|
|
|
def __grpcConfig(streamInfo: dict) -> dict: # gRPC传输方式配置 |
|
|
def __grpcConfig(streamInfo: dict) -> dict: # gRPC传输方式配置 |
|
|
grpcObject = {} |
|
|
|
|
|
return {**{ |
|
|
return {**{ |
|
|
'network': 'grpc', |
|
|
'network': 'grpc', |
|
|
'grpcSettings': grpcObject |
|
|
'grpcSettings': { |
|
|
|
|
|
'serviceName': streamInfo['service'] |
|
|
|
|
|
} |
|
|
}, **__secureConfig(streamInfo['secure'])} |
|
|
}, **__secureConfig(streamInfo['secure'])} |
|
|
|
|
|
|
|
|
def __vmessConfig(proxyInfo: dict) -> dict: # VMess节点配置 |
|
|
def __vmessConfig(proxyInfo: dict) -> dict: # VMess节点配置 |
|
@ -129,27 +190,8 @@ def load(proxyInfo: dict, socksPort: int, configFile: str) -> tuple[list or None |
|
|
载入成功: |
|
|
载入成功: |
|
|
return startCommand, fileContent, envVar |
|
|
return startCommand, fileContent, envVar |
|
|
""" |
|
|
""" |
|
|
|
|
|
try: |
|
|
config = __baseConfig(socksPort, __vmessConfig(proxyInfo)) |
|
|
config = __baseConfig(socksPort, __vmessConfig(proxyInfo)) |
|
|
|
|
|
|
|
|
return ['v2ray', '-c', configFile], json.dumps(config), {} |
|
|
return ['v2ray', '-c', configFile], json.dumps(config), {} |
|
|
|
|
|
except: |
|
|
info = { |
|
|
return None, None, None |
|
|
'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[1]) |
|
|
|
|
|