Browse Source

update: v2rayN encoder

dev
Dnomd343 2 years ago
parent
commit
0ec235cdff
  1. 68
      Encoder/VMess.py
  2. 2
      encoder_test.py

68
Encoder/VMess.py

@ -1,6 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
from Utils.Common import b64Encode
from Utils.Common import urlEncode
@ -25,19 +26,68 @@ def v2rayN(info: dict, name: str) -> str:
}
stream = info['stream']
if stream['type'] == 'tcp':
config['net'] = stream['type']
...
if stream['type'] == 'tcp':
if stream['obfs'] is None:
config.update({
'type': 'none',
'host': '',
'path': '',
})
else:
config.update({
'type': 'http',
'host': stream['obfs']['host'],
'path': stream['obfs']['path'],
})
elif stream['type'] == 'kcp':
...
config.update({
'type': stream['obfs'],
'host': '',
'path': '' if stream['seed'] is None else stream['seed'],
})
elif stream['type'] == 'ws':
...
config.update({
'type': 'none',
'host': stream['host'],
'path': stream['path'], # TODO: add `ed` field
})
elif stream['type'] == 'h2':
...
config.update({
'type': 'none',
'host': stream['host'],
'path': stream['path'],
})
elif stream['type'] == 'quic':
...
config.update({
'type': stream['obfs'],
'host': stream['method'],
'path': stream['passwd'],
})
elif stream['type'] == 'grpc':
...
config.update({
'type': stream['mode'],
'host': '',
'path': stream['service'],
})
secure = stream['secure']
if secure is None: # without TLS secure layer
config.update({
'tls': '',
'sni': '',
'alpn': '',
})
else:
config.update({
'tls': 'tls',
'sni': secure['sni'],
'alpn': '' if secure['alpn'] is None else secure['alpn'],
})
print(config)
print(info)
return 'vmess://%s' % b64Encode(
json.dumps(config, indent = 2).replace('\n', '\r\n'),
urlSafe = False,
padding = True,
)

2
encoder_test.py

@ -55,4 +55,4 @@ vmess_demo_1['info'] = Filter('vmess', vmess_demo_1['info'])
# print(vless_demo_1)
# print(vmess_demo_1)
Encoder.v2rayN(vmess_demo_1['info'], 'demo')
print(Encoder.v2rayN(vmess_demo_1['info'], 'demo'))

Loading…
Cancel
Save