# we only modify the config file at the pre-start stage if args.stage != 'pre-start': return
# read the content from the config.json conf_path = path.join(args.v2raya_confdir, 'config.json') withopen(conf_path) as f: conf = json.loads(f.read())
# append a socks with sniffing and routing rule inbound sniffing_socks = {'port': 11698, 'protocol': 'socks', 'listen': '0.0.0.0', 'sniffing': {'enabled': True}, 'tag': 'sniffing-socks'} conf['inbounds'].append(sniffing_socks)
# add routing rule support for this inbound (follow the rule port) for rule in conf['routing']['rules']: if'inboundTag'notin rule: continue with_rule = False for tag in rule['inboundTag']: if tag.startswith('rule-http'): with_rule = True break if with_rule: rule['inboundTag'].append(sniffing_socks['tag']) # write back to the file withopen(conf_path, 'w') as f: f.write(json.dumps(conf))