Michaelliv/flaregun
GitHub: Michaelliv/flaregun
基于 Cloudflare Workers 构建的轻量级轮换代理网络工具,一条命令即可部署多个具备不同出口 IP 的代理节点,支持 CLI、本地代理服务器和 SDK 三种使用方式。
Stars: 42 | Forks: 1
# flaregun 🔥
基于 Cloudflare Workers 的轮换代理网络。部署、轮换、开火。
将 Cloudflare 的免费层转变为轮换代理网络。部署 N 个 Workers,每个通过不同的 IP 出口。可用作直接替换的 `fetch`、本地代理服务器或 CLI。每日 10 万次请求免费。
```
npm install -g @miclivs/flaregun
```
## 快速开始
```
flaregun init --token cf_xxx --account abc123
flaregun up 5
flaregun fire https://httpbin.org/ip --count 3
```
每个请求显示不同的 IP。就是这样。
## CLI
```
flaregun init # create .flaregun/ config
flaregun init --token T --account A # with credentials
flaregun up 10 # deploy 10 proxy workers
flaregun up 5 # add 5 more (15 total)
flaregun ls # list deployed workers
flaregun fire # fire a request through proxy
flaregun fire -n 5 # fire 5 requests (rotated)
flaregun fire -m POST # POST request
flaregun serve # start local proxy on :8080
flaregun serve -p 3128 -s adaptive # custom port & strategy
flaregun down # teardown all workers
```
## 本地代理服务器
启动一个代理服务器,并在任何工具、任何语言中使用它:
```
flaregun serve --port 8080
```
```
# curl
curl --proxy http://localhost:8080 https://httpbin.org/ip
# python
requests.get("https://httpbin.org/ip", proxies={"http": "http://localhost:8080"})
# playwright
browser.launch({ proxy: { server: "http://localhost:8080" } })
```
实时请求日志流传输到 stdout —— 每个请求都会显示处理该请求的 worker、状态和延迟。
## SDK
```
import { FlareGun } from "flaregun";
const fg = new FlareGun({
apiToken: process.env.CLOUDFLARE_API_TOKEN,
accountId: process.env.CLOUDFLARE_ACCOUNT_ID,
});
// Deploy 5 workers
await fg.up(5);
// Drop-in fetch — automatically rotates
const res = await fg.fetch("https://httpbin.org/ip");
console.log(await res.json()); // { origin: "104.28.x.x" }
const res2 = await fg.fetch("https://httpbin.org/ip");
console.log(await res2.json()); // { origin: "172.67.x.x" } — different IP
// Or start a local proxy server
await fg.serve({ port: 8080, strategy: "adaptive" });
// Scale up/down
await fg.scale(20); // now 20 workers
await fg.scale(3); // scaled down to 3
// Get all URLs for external use
console.log(fg.urls());
// Cleanup
await fg.down();
```
## 轮换策略
| 策略 | 行为 |
|---|---|
| `round-robin` | 按顺序循环使用 workers(默认) |
| `random` | 每次请求随机选择 worker |
| `adaptive` | 自动回避收到 429/5xx 响应的 workers,采用指数退避冷却 |
## 配置
凭证按以下顺序解析:显式配置 → 环境变量 → 项目 `.flaregun/config.json` → 全局 `~/.flaregun/config.json`。
```
# 一次性设置 (保存至 ~/.flaregun/)
flaregun init --token xxx --account yyy
# 或使用 env vars
export CLOUDFLARE_API_TOKEN=your_token
export CLOUDFLARE_ACCOUNT_ID=your_account_id
# 或项目级 config
flaregun init --global false
```
## Cloudflare 设置
### 1. 创建免费账户
在 [dash.cloudflare.com/sign-up](https://dash.cloudflare.com/sign-up) 注册。
### 2. 创建 API token
1. 前往 **My Profile → API Tokens** ([直接链接](https://dash.cloudflare.com/profile/api-tokens))
2. 点击 **Create Token**
3. 找到 **Edit Cloudflare Workers** 并点击 **Use template**
4. 在 **Account Resources** 下,从下拉菜单中选择您的账户
5. 其他选项保持默认
6. 点击 **Continue to summary → Create Token**
7. 复制该 token
### 3. 获取您的 Account ID
您的 Account ID 位于 Cloudflare dashboard URL 中:`dash.cloudflare.com//...`
或者在 **Workers & Pages** 概览页面的右侧边栏中找到它。
### 4. 配置 flaregun
```
flaregun init --token cfut_xxx --account abc123
```
这会将凭证保存到 `~/.flaregun/config.json` —— 可在所有项目中全局使用。您已准备就绪:
```
flaregun up 5
flaregun fire https://httpbin.org/ip
```
### 限制
| 计划 | 请求量 | 费用 |
|---|---|---|
| Free | 10 万次/天 | $0 |
| Paid | 包含 1000 万次/月 | $5/月 + $0.30/百万次 |
## 用于 Agents
每个命令都支持 `--json` 以进行结构化输出:
```
flaregun ls --json
flaregun fire https://httpbin.org/ip --json
```
## 许可证
MIT
标签:API代理, GNU通用公共许可证, IP 地址批量处理, IP轮换, MITM代理, Node.js, npm, Serverless, Web代理, 云计算, 代理网络, 免费节点, 匿名代理, 暗色界面, 流量伪装, 爬虫代理, 程序员工具, 网络安全, 网络请求, 自动化攻击, 规则引擎, 轮换代理, 隐私保护