Skip to main content

Automated-sing-box-json-generator

Sing-box + Cloudflare WARP 一键自动部署工具。

支持 AnyTLS (Reality) / TUIC / Hysteria2 三协议可选组合,自动完成依赖安装、DNS 记录创建、TLS 证书签发、配置生成、Watchdog 守护部署。


快速开始

推荐方式:通过 pip 安装

pip install automated-sing-box-generator
automated-sing-box-generator deploy

开发者方式:从源码运行

git clone https://github.com/henryliu443/Automated-sing-box-json-generator.git
cd Automated-sing-box-json-generator
pip install -e .
automated-sing-box-generator deploy

部署过程中会交互式提示输入:

  1. 主域名(如 example.com)
  2. Cloudflare API Token 和 Zone ID
  3. 要启用的协议(默认全选)

CLI 子命令

命令 说明
automated-sing-box-generator 无参数默认执行完整部署
automated-sing-box-generator deploy 完整部署(可选 --domain / --protocols)
automated-sing-box-generator install 仅安装依赖(WARP、sing-box)
automated-sing-box-generator config 管理配置和凭据(--protocols 切换协议,或 --api 重新部署)
automated-sing-box-generator export 导出客户端配置(--format json|link,--output 指定文件)
automated-sing-box-generator doctor 系统诊断与状态检查(可选 --status / --validate / --benchmark)
automated-sing-box-generator manage 高级维护工具(子命令:update / certs / watchdog / cleanup-dns)
automated-sing-box-generator uninstall 完整卸载工具部署的所有组件(可带 --remove-warp)

示例

# 非交互式部署,仅启用 AnyTLS 和 TUIC
automated-sing-box-generator deploy --domain example.com --protocols anytls,tuic

# 导出分享链接
automated-sing-box-generator export --format link

# 导出客户端 JSON 到 file
automated-sing-box-generator export --format json --output client.json


# 切换到仅 Hysteria2
automated-sing-box-generator config --protocols hy2

# 重新生成全部凭据并重新部署 (等同于旧版 redeploy)
automated-sing-box-generator config --api

# 检查服务运行状态 (等同于旧版 status)
automated-sing-box-generator doctor --status

# 升级 sing-box 版本 (等同于旧版 update)
automated-sing-box-generator manage update

核心特性

协议可选化

部署时交互选择或通过 --protocols 指定要启用的协议组合:

  • AnyTLS (Reality) — TCP,无需 TLS 证书,使用 Reality 伪装
  • TUIC — UDP/QUIC,需要 TLS 证书
  • Hysteria2 — UDP/QUIC,需要 TLS 证书

仅启用 AnyTLS 时无需签发证书,部署更快。

路由模式(route-mode)

客户端配置内置三层出站架构,通过顶层 route-mode selector 在客户端 UI 一键切换:

模式 未匹配流量 DNS(未匹配域名) 推荐场景
route(默认) 直连 1.1.1.1 DoH via 代理 日常使用,规则分流
global 走代理节点(含 direct 规则) 1.1.1.1 DoH via 代理 需要全局翻墙、测试连通性
direct 直连 1.1.1.1 DoH via 代理 临时关闭代理、排查网络问题

三层结构:

route-mode (selector)          ← route.final 指向这里
├── route   (direct)           ← 默认,规则分流
├── global  (selector)         ← 全局代理,可手动选节点或 proxy-auto
│   ├── proxy-auto (urltest)   ← 自动测速选最优
│   ├── anytls-out / tuic-out / hy2-out
│   └── route                  ← 兜底回退到直连
└── direct  (direct)           ← 全部直连

注意:切到 global 时,分流规则的结果会收敛到代理出口(等价全局代理);仅保留私网地址直连以保证局域网访问稳定。

排查指南:

现象 排查步骤
全局模式下某些网站打不开 切到 global → 确认 proxy-auto 已选中且测速通过;若节点全挂,在 global 里手动切到 route 兜底
规则模式下国内网站走了代理 检查 rules.json 的 direct_suffix 是否包含该域名,或确认 GEOSITE-CN 规则集已下载
DNS 解析慢 DNS final 为 dns-remote(1.1.1.1 DoH via 代理),若代理延迟高会影响首次解析;已匹配的国内域名走 dns-direct(223.5.5.5)不受影响
想临时绕过大部分代理 切 route-mode → direct;显式 proxy 规则仍生效

DNS 记录自动管理

部署时自动通过 Cloudflare API:

  • 为每个协议生成随机子域名前缀(每次部署唯一,不在代码中硬编码)
  • 检测服务器公网 IP
  • 自动创建 A 记录,IP 变更时自动更新
  • 协议切换时自动清理不再需要的记录
  • 所有记录打上 managed:sing-box-deploy 标识,不会误删用户其他 DNS 记录

凭据安全

  • 每次部署随机生成 UUID、Reality 密钥对、各协议独立密码、随机 short_id
  • 凭据存储于 VPS 本地 /etc/sing-box/deploy-state.json(权限 0600,仅 root 可读)
  • 服务端配置 /etc/sing-box/config.json 同样 0600 权限
  • 代码仓库中不含任何硬编码凭据或子域名前缀
  • deploy-state.json 已加入 .gitignore

客户端导出

  • JSON — 完整 sing-box 客户端配置,可直接导入 GUI 客户端
  • Share Link — 标准 URI 格式(tuic://、hy2://、anytls://)

WARP 集成

  • 自动安装官方 Cloudflare WARP(warp-svc + warp-cli)
  • 自动识别本地代理模式(127.0.0.1:40000)与系统隧道模式
  • 集成 Watchdog 守护脚本,每分钟检测 WARP 健康状态,自动重连/重注册

其他

  • TLS 证书通过 acme.sh + Cloudflare DNS-01 自动签发和续签
  • sing-box 自动更新定时任务(每日凌晨检查 GitHub Latest Release)
  • 端口冲突自动检测
  • 部署状态持久化,支持重新生成配置和导出而无需重新部署

部署流程

输入主域名 + CF 凭据 + 选择协议
        │
        ▼
  生成随机子域名前缀
        │
        ▼
  检测服务器公网 IP → Cloudflare API 创建 A 记录
        │
        ▼
  安装依赖 (WARP + sing-box) + 端口检查
        │
        ▼
  签发 TLS 证书 (仅 TUIC/Hy2 需要)
        │
        ▼
  生成随机凭据 → 写入服务端配置 + 保存部署状态
        │
        ▼
  部署 Watchdog → 重启 sing-box → 输出客户端配置

项目结构

文件 说明
cli.py CLI 入口,argparse 子命令分发
deploy.py 核心部署/重配置/状态查看流程
config.py 服务端/客户端 sing-box 配置生成(按协议动态组装)
cloudflare_dns.py Cloudflare API DNS 记录管理(创建/更新/清理)
credentials.py UUID、Reality 密钥、随机密码、子域名前缀生成
certs.py acme.sh + Cloudflare DNS-01 证书签发
installer.py WARP、sing-box 安装与端口检查
state.py 部署状态持久化(/etc/sing-box/deploy-state.json)
export.py 客户端配置导出(JSON / Share Link / QR)
watchdog.py WARP Watchdog 脚本生成与 crontab 挂载
route_profile.py 客户端路由规则与 DNS 配置
ui.py 终端 UI 输出函数

Cloudflare 凭据

需要一个具有 DNS 编辑权限 的 Cloudflare API Token 和对应的 Zone ID。

提供方式(二选一):

  1. 运行时交互输入(部署时会自动提示)
  2. 环境变量(运行前导出):
export CF_Token="你的 Cloudflare API Token"
export CF_Zone_ID="你的 Zone ID"

这些凭据不会被持久化到磁盘,仅在部署过程中使用。


安全说明

本项目设计为公开仓库安全存储:

  • 所有敏感数据(密码、私钥、子域名前缀)在部署时动态生成,存储于 VPS 的 0600 文件中
  • 代码中不含任何硬编码凭据
  • Cloudflare API Token 仅在内存中使用,不写入磁盘
  • DNS 记录通过 API comment 标识,清理时不会误删用户其他记录

Metadata

Release files for automated-sing-box-generator 0.3.36

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for automated-sing-box-generator 0.3.36
File Size Uploaded Provenance Actions
automated_sing_box_generator-0.3.36.tar.gz 68.7 kB With provenance Details for automated_sing_box_generator-0.3.36.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for automated-sing-box-generator 0.3.36
File Interpreter ABI Platform Actions
automated_sing_box_generator-0.3.36-py3-none-any.whl Python 3 none any Details for automated_sing_box_generator-0.3.36-py3-none-any.whl

Total release size: 138.7 kB

Release files / automated_sing_box_generator-0.3.36.tar.gz

Download URL automated_sing_box_generator-0.3.36.tar.gz
Size 68.7 kB
Tags Source
SHA-256 checksum
How to use checksums
be35c81753b96be9642db3a0dfa8563932500a424b3bfe9750e1bb8c53974178
BLAKE2b-256 checksum
How to use checksums
9f09d55c3106f8c1b96beaa3dc5461b6a07e33c82d921bb0427ebc5f1289def1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release files / automated_sing_box_generator-0.3.36-py3-none-any.whl

Download URL automated_sing_box_generator-0.3.36-py3-none-any.whl
Size 70.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0879d73096bd3168e68911f5c8eef318bedeca4a7396df51f44c45e24fbfacc5
BLAKE2b-256 checksum
How to use checksums
6a738451a5419e39308e9650ec1c832b90db716cf6a2390e3c76e192c36f2907
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Security for automated-sing-box-generator 0.3.36

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for automated_sing_box_generator-0.3.36.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.36 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page