Created
June 24, 2022 04:14
-
-
Save i-sync/f5a6ddbf2fb17284f8ed3b84597e6123 to your computer and use it in GitHub Desktop.
v2ray connection parser
This file contains 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/python3 | |
from audioop import add | |
import os, json | |
def main(): | |
outbounds = [] | |
inbounds = [] | |
inbound_template = """ | |
{{ | |
"tag": "{0}", | |
"port": "{0}", | |
"listen": "127.0.0.1", | |
"protocol": "http", | |
"settings": {{ | |
"auth": "noauth", | |
"udp": "False", | |
"ip": "127.0.0.1" | |
}} | |
}} | |
""" | |
proxies = [] | |
proxy_template = """ | |
{{ | |
"ip": "127.0.0.1", | |
"port": "{0}", | |
"protocols": "http" | |
}} | |
""" | |
#inbound_template = '\{"tag":"{0}","port":"{0}","listen":"127.0.0.1","protocol":"http","settings":\{"auth":"noauth","udp":False,"ip":"127.0.0.1"\}\}' | |
start_port = 11000 | |
for filename in os.listdir("."): | |
print(filename) | |
with open(filename, 'r', encoding='utf-8') as f: | |
#print(f.readlines()) | |
if not filename.endswith(".json"): | |
continue | |
try: | |
config = json.load(f) | |
except Exception as e: | |
print(filename, "----------") | |
break | |
outbound = config["outbounds"][0] | |
address = outbound["settings"]["vnext"][0]["address"] | |
print(address) | |
if address.find("viagle") == -1: | |
outbound["tag"] = f"{start_port}" | |
outbounds.append(outbound) | |
inbound = inbound_template.format(start_port) | |
inbounds.append(json.loads(inbound)) | |
proxy = proxy_template.format(start_port) | |
proxies.append(json.loads(proxy)) | |
start_port += 1 | |
with open("result.out", 'w+', encoding='utf-8') as f: | |
json.dump(outbounds, f, indent=4) | |
with open("result.in", 'w+', encoding='utf-8') as f: | |
json.dump(inbounds, f, indent=4) | |
with open("result.proxy", 'w+', encoding='utf-8') as f: | |
json.dump(proxies, f, indent=4) | |
print("done") | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment