1
0
mirror of https://github.com/nitezs/sub2sing-box.git synced 2024-12-23 14:34:41 -05:00
sub2sing-box/README.md

128 lines
2.6 KiB
Markdown
Raw Normal View History

2024-03-19 01:55:31 -04:00
# sub2sing-box
2024-10-02 13:43:42 -04:00
将订阅/节点连接转换为 sing-box 配置的工具。
2024-03-19 01:55:31 -04:00
2024-10-02 13:43:42 -04:00
## 控制台命令
2024-03-19 01:55:31 -04:00
2024-10-02 13:43:42 -04:00
使用 `sub2sing-box <command> -h` 查看各命令的帮助信息。
2024-03-19 01:55:31 -04:00
2024-10-02 13:43:42 -04:00
## 配置
2024-03-19 01:55:31 -04:00
2024-10-02 13:43:42 -04:00
示例:
2024-03-19 05:20:58 -04:00
2024-10-02 13:43:42 -04:00
```json
2024-03-19 01:55:31 -04:00
{
2024-03-19 09:02:53 -04:00
"subscriptions": ["订阅地址1", "订阅地址2"],
"proxies": ["代理1", "代理2"],
2024-10-02 13:43:42 -04:00
"template": "模板路径或网络地址",
2024-10-21 03:56:12 -04:00
"delete": "剩余流量",
2024-10-02 13:43:42 -04:00
"rename": { "原文本": "新文本" },
2024-03-19 09:02:53 -04:00
"group-type": "selector",
"sort": "name",
2024-10-21 03:56:12 -04:00
"sort-type": "asc",
"output": "./config.json"
2024-03-19 01:55:31 -04:00
}
```
2024-10-21 03:56:12 -04:00
将上述 JSON 内容保存为 `sub2sing-box.json`,执行:
2024-10-02 13:43:42 -04:00
```
2024-10-21 03:56:12 -04:00
sub2sing-box convert -c ./sub2sing-box.json
2024-10-02 13:43:42 -04:00
```
即可生成 sing-box 配置,无需每次重复设置参数。
2024-10-01 00:45:55 -04:00
2024-10-02 13:43:42 -04:00
## 模板
### 默认模板
2024-10-21 03:56:12 -04:00
默认模板位于 `templates` 目录,使用 `tun` 配置,可以根据需求自行修改模板内容。
2024-10-02 13:43:42 -04:00
### 占位符
模板中可使用以下占位符:
2024-03-19 01:55:31 -04:00
2024-03-19 09:02:53 -04:00
- `<all-proxy-tags>`: 插入所有节点标签
- `<all-country-tags>`: 插入所有国家标签
2024-10-02 13:43:42 -04:00
- `<国家(地区)二字码>`: 插入指定国家(地区)所有节点标签,如 `<tw>`
2024-10-01 00:50:40 -04:00
2024-10-21 03:56:12 -04:00
#### 占位符使用示例:
假设有节点:
- US
- SG
- TW
2024-10-02 13:43:42 -04:00
```json
{
"type": "selector",
"tag": "节点选择",
"outbounds": ["<all-proxy-tags>", "direct"],
"interrupt_exist_connections": true
}
2024-10-21 03:56:12 -04:00
// 转换后
{
"type": "selector",
"tag": "节点选择",
"outbounds": ["US", "SG", "TW", "direct"],
"interrupt_exist_connections": true
}
```
```json
2024-10-02 13:43:42 -04:00
{
"type": "selector",
"tag": "节点选择",
"outbounds": ["<all-country-tags>", "direct"],
"interrupt_exist_connections": true
}
2024-10-21 03:56:12 -04:00
// 转换后
{
"type": "selector",
"tag": "节点选择",
"outbounds": ["美国(US)", "新加坡(SG)", "台湾(TW)", "direct"],
"interrupt_exist_connections": true
}
// 其中 "美国(US)", "新加坡(SG)", "台湾(TW)" 为策略组,分别包含 US, SG, TW 节点
```
```json
2024-10-02 13:43:42 -04:00
{
"type": "selector",
"tag": "巴哈姆特",
"outbounds": ["<tw>", "direct"],
"interrupt_exist_connections": true
}
2024-10-21 03:56:12 -04:00
// 转换后
{
"type": "selector",
"tag": "巴哈姆特",
"outbounds": ["台湾(TW)", "direct"],
"interrupt_exist_connections": true
}
2024-10-02 13:43:42 -04:00
```
## Docker 使用
```
2024-10-21 03:56:12 -04:00
docker run -p 8080:8080 nite07/sub2sing-box:latest
2024-10-02 13:43:42 -04:00
```
可以挂载目录添加自定义模板
## Server 模式 API
### GET /convert
2024-10-01 00:50:40 -04:00
2024-10-02 13:43:42 -04:00
| query | 描述 |
| ----- | ----------------------------------------------------------------------------------------------------------------------- |
| data | 同上方配置,但需要使用 [base64 URL safe 编码](<https://gchq.github.io/CyberChef/#recipe=To_Base64('A-Za-z0-9%2B/%3D')>) |