From 555419d98f018c0f99f95cc7104a0a7f8cbf6eed Mon Sep 17 00:00:00 2001 From: shevonkuan Date: Tue, 3 Jan 2023 16:43:44 +0800 Subject: [PATCH] Add VLESS encoder --- Encoder/VLESS.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/Encoder/VLESS.py b/Encoder/VLESS.py index 738bd48..abf3b6e 100644 --- a/Encoder/VLESS.py +++ b/Encoder/VLESS.py @@ -1,7 +1,39 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +from Utils.Common import urlEncode -def vless(info: dict) -> str: +def vless(info: dict, name: str) -> str: """ https://github.com/XTLS/Xray-core/discussions/716 + + FORMAT: protocol://$(uuid)@remote-host:remote-port?#$(descriptive-text) """ + + link = 'vless://' + link += info['id'] + '@' # add + link += info['server'] + ':' # add + link += str(info['port']) + '?' # add + + # stream settings + streamInfo = info['stream']['type'] + type = streamInfo['type'] + flow = streamInfo.get('flow', None) + headerType = streamInfo.get('obfs', 'none') + host = streamInfo.get('host', None) + path = streamInfo.get('path', None) + security = streamInfo.get('secure', None) + alpn = streamInfo.get('alpn', None) + sni = streamInfo.get('sni', None) + + link += 'type=' + type + '&' # add + link += 'flow=' + flow + '&' if flow else '' # add + link += 'headerType=' + headerType + '&' # add + link += 'security=' + security + '&' if security else '' # add + link += 'alpn=' + alpn + '&' if alpn else '' # add + link += 'sni=' + sni + '&' if sni else '' # add + link += 'host=' + host + '&' if host else '' # add + link += 'path=' + path + '&' if path else '' # add + + link += '#' + urlEncode(name) # add + print(link) + return link \ No newline at end of file