Last active
January 12, 2026 08:30
-
-
Save graythze/432978a0e15d58f42b95092702adce5e to your computer and use it in GitHub Desktop.
AmneziaVPN XRay to XRay Native
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import urllib.parse | |
| import os | |
| def convert_json_to_vless(json_file, custom_name): | |
| # Читаем JSON-файл | |
| with open(json_file, 'r') as f: | |
| config = json.load(f) | |
| # Извлекаем необходимые данные | |
| outbound = config['outbounds'][0] | |
| vnext = outbound['settings']['vnext'][0] | |
| user = vnext['users'][0] | |
| reality = outbound['streamSettings']['realitySettings'] | |
| # Собираем параметры | |
| vless_params = { | |
| 'id': user['id'], | |
| 'address': vnext['address'], | |
| 'port': vnext['port'], | |
| 'security': outbound['streamSettings']['security'], | |
| 'sni': reality['serverName'], | |
| 'fp': reality['fingerprint'], | |
| 'pbk': reality['publicKey'], | |
| 'sid': reality['shortId'], | |
| 'type': outbound['streamSettings']['network'], | |
| 'flow': user['flow'], | |
| 'encryption': user['encryption'] | |
| } | |
| # Формируем URL | |
| vless_url = (f"vless://{vless_params['id']}@{vless_params['address']}:{vless_params['port']}" | |
| f"?security={vless_params['security']}" | |
| f"&sni={urllib.parse.quote(vless_params['sni'])}" | |
| f"&fp={vless_params['fp']}" | |
| f"&pbk={urllib.parse.quote(vless_params['pbk'])}" | |
| f"&sid={vless_params['sid']}" | |
| f"&type={vless_params['type']}" | |
| f"&flow={vless_params['flow']}" | |
| f"&encryption={vless_params['encryption']}" | |
| f"#{urllib.parse.quote(custom_name)}") | |
| return vless_url | |
| def save_to_file(vless_url, custom_name): | |
| # Формируем имя файла на основе custom_name | |
| output_file = f"{custom_name}.txt" | |
| # Заменяем недопустимые символы в имени файла | |
| safe_name = "".join(c for c in custom_name if c.isalnum() or c in ('-', '_')).rstrip() | |
| if not safe_name: | |
| safe_name = "Amnezia-VLESS" # Имя по умолчанию, если после очистки имя пустое | |
| output_file = f"{safe_name}.txt" | |
| # Сохраняем результат в текстовый файл | |
| with open(output_file, 'w') as f: | |
| f.write(vless_url) | |
| print(f"Ключ сохранен в файл: {output_file}") | |
| # Использование скрипта | |
| if __name__ == "__main__": | |
| json_file = "amnezia_for_xray.json" | |
| # Запрашиваем у пользователя имя для ключа | |
| custom_name = input("Введите имя для ключа VLESS (например, My-VLESS): ").strip() | |
| if not custom_name: | |
| custom_name = "Amnezia-VLESS" # Имя по умолчанию, если пользователь ничего не ввел | |
| # Конвертируем JSON в ключ VLESS | |
| vless_key = convert_json_to_vless(json_file, custom_name) | |
| # Выводим ключ в консоль | |
| print("Сгенерированный ключ VLESS:") | |
| print(vless_key) | |
| # Сохраняем ключ в файл с именем, основанным на custom_name | |
| save_to_file(vless_key, custom_name) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From amnezia-vpn/amnezia-client#1595 (comment)