
Security News
Astral Launches pyx: A Python-Native Package Registry
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
一个基于 Node.js 的命令行代理工具,类似于 Clash,支持多种代理协议和智能分流规则。
安装依赖
# npm
npm i clash-node -g
# yarn
yarn global add clash-node
# pnpm
pnpm add clash-node -g
启动代理服务
# 使用默认配置启动(默认端口 7890)
cn start
# 指定端口启动
cn start -p 7890 -s 7891
# 添加订阅
cn list -a https://example.com/clash-config
# 列出所有订阅
cn list
# 更新订阅
cn update
# 删除订阅
cn subscription -d subscription-name
# 列出所有节点
cn node -l
# 选择节点
cn node -s "Node Name"
# 测试节点延迟
cn node -t
# 自动选择最快节点
cn node -a
# 查看代理状态
cn proxy --status
# 启用系统代理
cn proxy --enable
# 禁用系统代理
cn proxy --disable
cn status
自定义配置文件
# 使用自定义配置文件
cn start -c /path/to/config.yaml
默认配置文件位于 ./config/config.yaml
,支持以下配置:
# 代理端口
port: 7890
socks-port: 7891
# 允许局域网连接
allow-lan: false
# 代理模式:rule | global | direct
mode: rule
# 日志级别
log-level: info
# 外部控制器
external-controller: 127.0.0.1:9090
# 代理节点
proxies:
- name: "Example"
type: ss
server: example.com
port: 8388
cipher: aes-256-gcm
password: password
# 代理组
proxy-groups:
- name: PROXY
type: select
proxies:
- DIRECT
- AUTO
- name: AUTO
type: url-test
proxies: []
url: "http://www.gstatic.com/generate_204"
interval: 300
# 分流规则
rules:
- DOMAIN-SUFFIX,local,DIRECT
- IP-CIDR,127.0.0.0/8,DIRECT
- IP-CIDR,172.16.0.0/12,DIRECT
- IP-CIDR,192.168.0.0/16,DIRECT
- IP-CIDR,10.0.0.0/8,DIRECT
- GEOIP,CN,DIRECT
- MATCH,PROXY
启动服务后,可以通过 RESTful API 进行管理:
# 获取状态
curl http://127.0.0.1:9090/status
# 获取节点列表
curl http://127.0.0.1:9090/nodes
# 选择节点
curl -X POST http://127.0.0.1:9090/nodes/NodeName/select
# 测试节点
curl -X POST http://127.0.0.1:9090/nodes/NodeName/test
# 启用系统代理
curl -X POST http://127.0.0.1:9090/system-proxy/enable
# 禁用系统代理
curl -X POST http://127.0.0.1:9090/system-proxy/disable
连接到 ws://127.0.0.1:9090/ws
可以接收实时状态更新:
const ws = new WebSocket("ws://127.0.0.1:9090/ws");
ws.on("message", (data) => {
const message = JSON.parse(data);
console.log("Received:", message);
});
// 发送消息
ws.send(
JSON.stringify({
type: "getStatus",
})
);
- name: "http-example"
type: http
server: example.com
port: 8080
username: user
password: pass
- name: "socks5-example"
type: socks5
server: example.com
port: 1080
username: user
password: pass
支持以下规则类型:
DOMAIN-SUFFIX,example.com,PROXY
- 域名后缀匹配DOMAIN-KEYWORD,ads,REJECT
- 域名关键字匹配IP-CIDR,192.168.0.0/16,DIRECT
- IP 段匹配GEOIP,CN,DIRECT
- 地理位置匹配MATCH,PROXY
- 最终匹配规则在 macOS 上配置系统代理需要管理员权限:
sudo clash-node proxy --enable
确保防火墙允许代理端口通信:
# macOS
sudo pfctl -f /etc/pf.conf
# Windows
netsh advfirewall firewall add rule name="Clash Proxy" dir=in action=allow protocol=TCP localport=7890
如果遇到 DNS 解析问题,可以手动配置 DNS:
dns:
enable: true
nameserver:
- 8.8.8.8
- 1.1.1.1
clash-node/
├── bin/
│ └── cli.js # 命令行入口
├── src/
│ ├── core/
│ │ ├── ProxyManager.js # 代理管理器
│ │ ├── SystemProxy.js # 系统代理设置
│ │ ├── SubscriptionManager.js # 订阅管理
│ │ ├── ConfigManager.js # 配置管理
│ │ ├── RuleEngine.js # 规则引擎
│ │ └── NodeManager.js # 节点管理
│ └── index.js # 主服务
├── config/
│ ├── config.yaml # 配置文件
│ └── subscriptions.json # 订阅配置
└── package.json
# 开发模式运行
npm run dev
# 运行测试
npm test
# 构建可执行文件
npm run build
欢迎提交 Issue 和 Pull Request!
MIT License
本工具仅供学习和研究使用,请遵守当地法律法规。
FAQs
A Node.js CLI proxy tool similar to Clash
The npm package clash-node receives a total of 3 weekly downloads. As such, clash-node popularity was classified as not popular.
We found that clash-node demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.