Created
January 12, 2026 09:28
-
-
Save pavlozt/50f0cbfa5caa1850c5b5d0fb1e9cd1a8 to your computer and use it in GitHub Desktop.
generate vless:// scheme url from xray naive json format config
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
| #!/usr/bin/env python3 | |
| # Based on: https://gist.github.com/graythze/432978a0e15d58f42b95092702adce5e | |
| import json | |
| import urllib.parse | |
| import sys | |
| def convert_json_to_vless(config_data, custom_name): | |
| # Extract necessary data from the JSON structure | |
| outbound = config_data['outbounds'][0] | |
| vnext = outbound['settings']['vnext'][0] | |
| user = vnext['users'][0] | |
| reality = outbound['streamSettings']['realitySettings'] | |
| # Collect parameters for the URI | |
| 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.get('flow', ''), | |
| 'encryption': user.get('encryption', 'none') | |
| } | |
| # Construct the VLESS 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 | |
| if __name__ == "__main__": | |
| # Read JSON data from stdin | |
| json_data = sys.stdin.read() | |
| if not json_data: | |
| print("Error: No JSON data received via stdin", file=sys.stderr) | |
| sys.exit(1) | |
| try: | |
| config = json.loads(json_data) | |
| except json.JSONDecodeError as e: | |
| print(f"Error parsing JSON: {e}", file=sys.stderr) | |
| sys.exit(1) | |
| # Prompt user for a configuration name | |
| custom_name = input("Enter a name for the VLESS key (e.g., My-VLESS): ").strip() | |
| if not custom_name: | |
| custom_name = "VLESS-Config" | |
| # Convert JSON to VLESS link | |
| vless_link = convert_json_to_vless(config, custom_name) | |
| # Output only the generated link | |
| print("\nGenerated VLESS Link:") | |
| print(vless_link) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment