Browse Source

feat: v2rayN encode framework

dev
Dnomd343 2 years ago
parent
commit
7df00bc45f
  1. 43
      Encoder/VMess.py
  2. 1
      Encoder/__init__.py
  3. 29
      encoder_test.py

43
Encoder/VMess.py

@ -0,0 +1,43 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from Utils.Common import b64Encode
from Utils.Common import urlEncode
def v2rayN(info: dict, name: str) -> str:
"""
https://github.com/2dust/v2rayN/wiki/%E5%88%86%E4%BA%AB%E9%93%BE%E6%8E%A5%E6%A0%BC%E5%BC%8F%E8%AF%B4%E6%98%8E(ver-2)
FORMAT: vmess://BASE64-ENCODED-JSON-STRING
fields => v(=2) / ps / add / port / id / aid / scy / net / type / host / path / tls / sni / alpn
"""
# TODO: base64 with `+` and `/`
# TODO: => not urlSafe and with padding
config = {
'v': '2',
'ps': urlEncode(name),
'add': info['server'],
'port': str(info['port']),
'id': info['id'],
'aid': str(info['aid']),
'scy': info['method'],
}
stream = info['stream']
if stream['type'] == 'tcp':
...
elif stream['type'] == 'kcp':
...
elif stream['type'] == 'ws':
...
elif stream['type'] == 'h2':
...
elif stream['type'] == 'quic':
...
elif stream['type'] == 'grpc':
...
print(config)
print(info)

1
Encoder/__init__.py

@ -2,3 +2,4 @@
# -*- coding: utf-8 -*-
from Encoder.VLESS import vless
from Encoder.VMess import v2rayN

29
encoder_test.py

@ -1,6 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import Encoder
from Filter import Filter
vless_demo_1 = {
@ -26,6 +27,32 @@ vless_demo_1 = {
}
}
vmess_demo_1 = {
'type': 'vmess',
'name': '🇭🇰 DataGrids DMIT VMess 1Gbps',
'info': {
'server': '54.142.232.16',
'port': 52227,
'method': 'auto',
'id': '75e6edee-2c30-41b0-9d88-676c4fb19ee8',
'aid': 0,
'stream': {
'type': 'ws',
'host': 'proxy.demo.com',
'path': '/vmessws',
'ed': 2048,
'secure': {
'sni': 'proxy.demo.com',
'alpn': None,
'verify': True
}
}
}
}
vless_demo_1['info'] = Filter('vless', vless_demo_1['info'])
vmess_demo_1['info'] = Filter('vmess', vmess_demo_1['info'])
# print(vless_demo_1)
# print(vmess_demo_1)
print(vless_demo_1)
Encoder.v2rayN(vmess_demo_1['info'], 'demo')

Loading…
Cancel
Save