Download generate_pool_native.py from cefrefdwe/warp-proxy-test-1769392021: direct link, hf CLI and curl.
- Browser
- Download file 7.15 kB
-
https://huggingface.co/spaces/cefrefdwe/warp-proxy-test-1769392021/resolve/main/generate_pool_native.py
- Command line
-
hf download hf://spaces/cefrefdwe/warp-proxy-test-1769392021/generate_pool_native.py
-
curl -L -o generate_pool_native.py https://huggingface.co/spaces/cefrefdwe/warp-proxy-test-1769392021/resolve/main/generate_pool_native.py
7.15 kB
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| """ | |
| WARP 纯 Python 注册机 (无外部依赖版 - 支持代理) | |
| 功能:模拟 Android 客户端注册 Cloudflare WARP,生成 WireGuard 配置。 | |
| 特点:内嵌 Curve25519 算法,支持 SOCKS5/HTTP 代理(用于突破 HF 封锁)。 | |
| """ | |
| import json | |
| import datetime | |
| import random | |
| import string | |
| import sys | |
| import os | |
| import base64 | |
| import struct | |
| import time | |
| import argparse | |
| import requests # 使用 requests 以支持代理 | |
| # ==================== Curve25519 纯 Python 实现 (迭代版) ==================== | |
| P = 2 ** 255 - 19 | |
| A = 486662 | |
| def expmod(b, e, m): | |
| if e == 0: return 1 | |
| t = expmod(b, e // 2, m) ** 2 % m | |
| if e & 1: t = (t * b) % m | |
| return t | |
| def inv(x): return expmod(x, P - 2, P) | |
| def add(n, m, d): | |
| (xn, zn), (xm, zm), (xd, zd) = n, m, d | |
| x = 4 * (xm * xn - zm * zn) ** 2 * zd | |
| z = 4 * (xm * zn - zm * xn) ** 2 * xd | |
| return (x % P, z % P) | |
| def double(n): | |
| (xn, zn) = n | |
| x = (xn ** 2 - zn ** 2) ** 2 | |
| z = 4 * xn * zn * (xn ** 2 + A * xn * zn + zn ** 2) | |
| return (x % P, z % P) | |
| def curve25519(n, base=9): | |
| one = (base, 1) | |
| two = double(one) | |
| # Montgomery Ladder (非递归实现) | |
| x0, z0 = 1, 0 | |
| x1, z1 = base, 1 | |
| for i in range(254, -1, -1): | |
| bit = (n >> i) & 1 | |
| if bit == 0: | |
| x1, z1 = add((x1, z1), (x0, z0), one) | |
| x0, z0 = double((x0, z0)) | |
| else: | |
| x0, z0 = add((x0, z0), (x1, z1), one) | |
| x1, z1 = double((x1, z1)) | |
| return (x0 * inv(z0)) % P | |
| def clamp(n): | |
| n &= ~7 | |
| n &= ~(128 << 8 * 31) | |
| n |= 64 << 8 * 31 | |
| return n | |
| def generate_keypair(): | |
| # 生成 32 字节随机私钥 | |
| priv_bytes = os.urandom(32) | |
| # 转换为整数 | |
| priv_int = int.from_bytes(priv_bytes, 'little') | |
| # Clamp | |
| priv_clamped = clamp(priv_int) | |
| # 生成公钥 | |
| pub_int = curve25519(priv_clamped) | |
| # 转换回字节 | |
| pub_bytes = pub_int.to_bytes(32, 'little') | |
| # Base64 编码 | |
| priv_b64 = base64.b64encode(priv_bytes).decode('utf-8') | |
| pub_b64 = base64.b64encode(pub_bytes).decode('utf-8') | |
| return priv_b64, pub_b64 | |
| # ==================== 注册逻辑 ==================== | |
| def gen_string(length): | |
| return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(length)) | |
| def register_warp(index, proxy_url=None): | |
| print(f"[{index}] 🔐 正在生成密钥对...") | |
| try: | |
| priv_key, pub_key = generate_keypair() | |
| except Exception as e: | |
| print(f"❌ 密钥生成失败: {e}") | |
| return None | |
| print(f"[{index}] 📡 正在向 Cloudflare 发送注册请求 (Proxy: {proxy_url or 'Direct'})...") | |
| # 构造请求头 | |
| install_id = gen_string(22) | |
| # FCM token 模拟 | |
| fcm_token = f"{install_id}:APA91b{gen_string(134)}" | |
| headers = { | |
| 'User-Agent': 'okhttp/3.12.1', | |
| 'CF-Client-Version': 'a-6.10-2158', | |
| 'Content-Type': 'application/json; charset=UTF-8', | |
| 'Host': 'api.cloudflareclient.com', | |
| 'Connection': 'Keep-Alive', | |
| 'Accept-Encoding': 'gzip', | |
| } | |
| # 构造请求体 | |
| data = { | |
| "key": pub_key, | |
| "install_id": install_id, | |
| "fcm_token": fcm_token, | |
| "tos": datetime.datetime.now().isoformat()[:-3] + "+08:00", | |
| "model": "PC", | |
| "serial_number": install_id, | |
| "locale": "zh_CN" | |
| } | |
| url = "https://api.cloudflareclient.com/v0a2158/reg" | |
| proxies_list = [] | |
| if proxy_url: | |
| proxies_list.append(('Proxy', { | |
| "http": proxy_url, | |
| "https": proxy_url | |
| })) | |
| proxies_list.append(('Direct', None)) | |
| for mode, current_proxies in proxies_list: | |
| print(f"[{index}] 📡 尝试注册 ({mode})...") | |
| try: | |
| response = requests.post(url, json=data, headers=headers, proxies=current_proxies, timeout=30) | |
| if response.status_code == 200: | |
| resp_data = response.json() | |
| # 提取配置信息 | |
| account_id = resp_data['id'] | |
| token = resp_data['token'] | |
| # 默认 Endpoint | |
| endpoint = "engage.cloudflareclient.com:2408" | |
| # 尝试获取分配的 IP | |
| v4 = resp_data['config']['interface']['addresses']['v4'] | |
| v6 = resp_data['config']['interface']['addresses']['v6'] | |
| print(f"[{index}] ✅ 注册成功! IP: {v4}") | |
| return { | |
| "id": index, | |
| "private_key": priv_key, | |
| "public_key": pub_key, | |
| "address_v4": v4, | |
| "address_v6": v6, | |
| "endpoint": endpoint, | |
| "account_id": account_id, | |
| "token": token, | |
| "created_at": time.time() | |
| } | |
| elif response.status_code == 429: | |
| print(f"[{index}] ⚠️ 请求太频繁 (429) - {mode}") | |
| time.sleep(2) | |
| else: | |
| print(f"[{index}] ❌ 注册失败: HTTP {response.status_code} - {mode}") | |
| except Exception as e: | |
| print(f"[{index}] ❌ 连接错误 ({mode}): {e}") | |
| return None | |
| def main(): | |
| parser = argparse.ArgumentParser(description="WARP 账号批量生成器") | |
| parser.add_argument("--count", type=int, default=5, help="生成数量") | |
| parser.add_argument("--proxy", type=str, help="代理地址 (例如 socks5://127.0.0.1:40000)") | |
| parser.add_argument("--output", type=str, default="ip_pool.json", help="输出文件") | |
| parser.add_argument("--append", action="store_true", help="追加模式") | |
| args = parser.parse_args() | |
| pool_size = args.count | |
| output_file = args.output | |
| proxy_url = args.proxy | |
| accounts = [] | |
| # 如果是追加模式,先读取旧文件 | |
| if args.append and os.path.exists(output_file): | |
| try: | |
| with open(output_file, 'r') as f: | |
| accounts = json.load(f) | |
| print(f"📖 已加载现有账号: {len(accounts)} 个") | |
| except: | |
| pass | |
| import concurrent.futures | |
| print(f"🚀 开始并发生成 {pool_size} 个账号...") | |
| new_accounts = [] | |
| with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor: | |
| futures = [executor.submit(register_warp, len(accounts) + i + 1, proxy_url) for i in range(pool_size)] | |
| for future in concurrent.futures.as_completed(futures): | |
| result = future.result() | |
| if result: | |
| new_accounts.append(result) | |
| if new_accounts: | |
| accounts.extend(new_accounts) | |
| # 写入文件 | |
| with open(output_file, 'w') as f: | |
| json.dump(accounts, f, indent=2) | |
| print(f"💾 已保存 {len(new_accounts)} 个新账号到 {output_file}") | |
| print(f"📚 总账号数: {len(accounts)}") | |
| else: | |
| print("⚠️ 本次未生成任何有效账号") | |
| if __name__ == "__main__": | |
| main() | |