File size: 2,891 Bytes
7f1450c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
WARP 注册机 (无依赖版)
使用 Python 调用 curl 命令来模拟 API 请求,规避库依赖问题。
"""
import os
import sys
import json
import time
import subprocess
import logging
import random
import datetime
# 配置
POOL_SIZE = 5
OUTPUT_FILE = "ip_pool.json"
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s')
logger = logging.getLogger("REG-BOT")
def gen_keys():
"""
生成 Curve25519 密钥对
注意:Python 原生不支持,这里我们尝试用 wgcf 的 key 生成功能,
或者如果没有 wgcf,我们只能依赖系统命令。
为了简化,我们继续尝试使用 bin/wgcf 只做生成密钥这一步(这一步不需要联网,不会报错)
"""
try:
# 使用 wgcf 生成私钥
# 这是一个 trick:wgcf 没有任何参数时不会报错,但我们无法直接调用它生成 key
# 所以我们改用 openssl (macOS 自带)
# 1. 生成私钥
priv_key = subprocess.check_output("openssl rand -base64 32", shell=True).decode().strip()
# 2. 生成公钥 (这就难了,OpenSSL 不直接支持 Curve25519 的转换)
# 我们还是得用 wgcf,但只用它来"生成配置"的副作用
# 抱歉,wgcf 必须注册后才能生成配置。
# 回退方案:我们假设 wgcf register 失败是因为网络,但我们看看能否欺骗它
pass
except:
pass
# 既然本地生成困难,我们换个思路。
# 我们直接使用 Cloudflare 的 API 注册,但我们需要能在 Python 里算 Key。
# 鉴于环境限制,我们还是得修好 wgcf。
return None
def main():
logger.info("⚠️ 检测到本地 wgcf 注册失败。尝试排查网络问题。")
# 检查 wgcf 是否存在
wgcf_bin = "bin/wgcf"
if not os.path.exists(wgcf_bin):
logger.error("❌ wgcf 二进制文件丢失")
return
# 尝试手动执行一次,看详细报错
logger.info("🔍 执行诊断测试...")
try:
res = subprocess.run([wgcf_bin, "register", "--accept-tos"], capture_output=True, text=True)
logger.info(f"Return Code: {res.returncode}")
logger.info(f"Stdout: {res.stdout}")
logger.info(f"Stderr: {res.stderr}")
if "429" in res.stderr or "Too Many Requests" in res.stderr:
logger.error("❌ 您的 IP 请求过多被限流了 (429)。请切换 Wi-Fi 或等待 1 小时。")
elif "403" in res.stderr or "Forbidden" in res.stderr:
logger.error("❌ 您的 IP 被 Cloudflare 封锁了 (403)。")
else:
logger.error("❌ 未知错误。")
except Exception as e:
logger.error(f"执行异常: {e}")
if __name__ == "__main__":
main()
|