Loading... # 引言 本网站不提供翻墙、代理等方法,此文章仅以学习ss和vmess编码的解析,切勿用于非法用途,否则后果自负。 本文章用于大量机器的代理操作,自己搭建的订阅池,用于本地局域网内的操作,因为部分网段需要隔离,通过这个方式打破隔离规则,相对来说比较隐蔽和安全。 # 思路 实际上都是base64的运用,只是ss的解密之后需要分割一下内容,如果需要变成v2ray可以读取的配置文件,稍加改造即可。代码是半成品,不提供完整代码。 # 代码 ```pthon import base64 import urllib.parse import requests import json import os base_config = { "log": { "access": "", "error": "", "loglevel": "warning" }, "inbounds": [ { "tag": "socks", "port": 10808, "listen": "0.0.0.0", "protocol": "socks", "sniffing": { "enabled": True, "destOverride": [ "http", "tls" ], "routeOnly": False }, "settings": { "auth": "noauth", "udp": True, "allowTransparent": False } }, { "tag": "http", "port": 10809, "listen": "0.0.0.0", "protocol": "http", "sniffing": { "enabled": True, "destOverride": [ "http", "tls" ], "routeOnly": False }, "settings": { "auth": "noauth", "udp": True, "allowTransparent": False } } ], "outbounds": [ { "tag": "proxy", "protocol": "vmess", "settings": { "vnext": [ { "address": "", "port": 1080, "users": [ { "id": "abcdefgh-1234-5678-9012-123456789789", "alterId": 1, "email": "admin@zunmx.top", "security": "auto" } ] } ] }, "streamSettings": { "network": "tcp" }, "mux": { "enabled": False, "concurrency": -1 } } ], "dns": { "hosts": { "dns.google": "8.8.8.8", "proxy.example.com": "127.0.0.1" }, "servers": [ { "address": "223.5.5.5", "domains": [ "geosite:cn", "geosite:geolocation-cn" ], "expectIPs": [ "geoip:cn" ] }, "1.1.1.1", "8.8.8.8", "https://dns.google/dns-query" ] } } config_dir = "c:\\tmp\\v2ray" def print_sub(*kwargs): print('debug', kwargs) class V2ray_CLI: def __init__(self): self.publish_url = '' # 订阅链接 self.publish_content = '' self.publish_decode = '' self.publish_items = [] def get_publish_content(self): print_sub('[#] 正在获取订阅信息') self.publish_content = requests.get(self.publish_url).text print_sub('[i] 获取完成') def get_publish_items(self): print_sub('[#] 正在解析订阅信息') self.publish_decode = base64.urlsafe_b64decode(self.publish_content).decode('utf-8') for i in self.publish_decode.split('\n'): if i.startswith('vmess://'): self.publish_items.append(i) elif i.startswith('ss://'): self.publish_items.append(i) def get_configure(self): print_sub('[#] 正在详细订阅信息') for i in self.publish_items: if i.startswith('vmess://'): link = i[8:] link = base64.urlsafe_b64decode(link).decode('utf-8') cfg = json.loads(link) name = cfg['ps'] current_config = json.loads(json.dumps(base_config)) current_config['outbounds'][0]['protocol'] = 'vmess' current_config['outbounds'][0]['settings']['vnext'][0]['address'] = cfg['add'] current_config['outbounds'][0]['settings']['vnext'][0]['port'] = int(cfg['port']) current_config['outbounds'][0]['settings']['vnext'][0]['users'][0]['id'] = cfg['id'] current_config['outbounds'][0]['settings']['vnext'][0]['users'][0]['alterId'] = int(cfg['aid']) current_config['outbounds'][0]['streamSettings']['network'] = cfg['net'] if cfg['tls'] == 'tls': current_config['outbounds'][0]['streamSettings']['security'] = 'tls' current_config['outbounds'][0]['streamSettings']['tlsSettings'] = { "allowInsecure": False, "show": False } elif i.startswith('ss://'): link = i[5:] name_idx = link.rfind('#') name = urllib.parse.unquote(link[name_idx + 1:]) link = base64.urlsafe_b64decode(link[:name_idx] + "==").decode('utf-8') current_config = json.loads(json.dumps(base_config)) current_config['outbounds'][0]['settings']['servers'] = base_config['outbounds'][0]['settings']['vnext'] del current_config['outbounds'][0]['settings']['vnext'] try: del current_config['outbounds'][0]['settings']['servers'][0]['users'] except Exception as e: pass protocol = 'shadowsocks' method = link[0:link.find(":")] password = link<div class="list-group list-group-lg list-group-sp row" style="margin: 0"></div> address = link<div class="list-group list-group-lg list-group-sp row" style="margin: 0"></div> port = link<div class="list-group list-group-lg list-group-sp row" style="margin: 0"></div> current_config['outbounds'][0]['protocol'] = protocol current_config['outbounds'][0]['settings']['servers'][0]['address'] = address current_config['outbounds'][0]['settings']['servers'][0]['port'] = int(port) current_config['outbounds'][0]['settings']['servers'][0]['password'] = password current_config['outbounds'][0]['settings']['servers'][0]['method'] = method current_config['outbounds'][0]['settings']['servers'][0]['level'] = 1 current_config['outbounds'][0]['settings']['servers'][0]['ota'] = False else: continue name = (name.replace("-", "_"). replace(" ", "_"). replace(":", "_"). replace(":", "_"). replace("%", "百分比"). replace("|", "_")) file_path = os.path.join(config_dir, name + ".json") try: with open(file_path, 'w') as f: f.write(json.dumps(current_config, indent=4, ensure_ascii=False)) except Exception as e: print_sub("[!] 写入配置文件失败", file_path) def test_config(self): print_sub('[#] 正在测试配置文件') listdir = os.listdir(config_dir) for i in listdir: if i.endswith(".json"): print(i) cli = V2ray_CLI() # cli.get_publish_content() # cli.get_publish_items() # cli.get_configure() cli.test_config() # v2ray run -config aaa.json ``` # 结论 请遵守当地法律法规! © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏