对网上warp生成WireGard配置脚本做分析记录,知其然且知其所以然。
脚本主要使用工具 wgcf
基础命令
注册
注册新的账号并把账号信息保存在wgcf-account.toml中 (这里是随意注册的一个账户)
1 2 3 4 5
| $ cat wgcf-account.toml access_token = 'bd88d432-9237-4edb-be29-d548913aaa3c' device_id = '1ddcf044-49f5-4a2b-b07e-5b6dea119f70' license_key = '02p3t7mN-z5Qu246C-k196XJA0' private_key = 'SO/R6UTO0rbizGiWT1iDRBpg1HWZRCdpa2V6GS7fmGw='
|
其中的license_key就是warp提供的Key
更新Key
修改wgcf-account.toml 文件中的license_key,然后执行
1
| wgcf update --name forg20240122
|
上面的--name参数是更新设备名称。
注意更新之后记得需要重新生成WireGuard的配置文件wgcf generate。生成之后就可以直接导入到支持WireGuard的工具中使用了。
生成配置
生成wgcf-profile.conf的WireGuard配置文件。
查看设备状态
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| wgcf status
2024/01/26 21:43:35 Using config file: wgcf-account.toml 2024/01/26 21:43:36 Setting device name 2024/01/26 21:43:38 ======================================= 2024/01/26 21:43:38 Device name : forg20240126 2024/01/26 21:43:38 Device model : PC 2024/01/26 21:43:38 Device active : true 2024/01/26 21:43:38 Account type : limited 2024/01/26 21:43:38 Role : child 2024/01/26 21:43:38 Premium data : 21.85 PiB 2024/01/26 21:43:38 Quota : 21.85 PiB 2024/01/26 21:43:38 ======================================= 2024/01/26 21:43:38 Successfully updated Cloudflare Warp account
|
上面是我使用自己的设备与Warp+的key生成的账户状态。
制品解析
使用replit 作为运行环境 https://replit.com/@misaka-blog/wgcf-profile-generator
开始解析网上流传的生成配置的shell脚本。
前置步骤
删除wgcf-account.toml与wgcf-profile.conf文件,相当于做下清理初始化。
随后执行wgcf register获得一个免费账户,并生成记录文件wgcf-account.toml
选项2
提示输入 Warp 的 key, 输入之后直接替换账户文件wgcf-account.toml中的license_key配置,然后提示输入自定义的设备名称。
随后使用wgcf update更新账户信息,继续使用wgcf generate生成配置文件wgcf-profile.conf。
选项3
使用当前的wgcf-account.toml账户信息生成配置文件wgcf-profile.conf。
随后让用户选择使用Teams TOKEN或者使用提取出来的xml 配置。
先看xml配置导入:
- 提取配置
- 填入git gist
- 从git gist下载到服务器
- 解析出私钥,地址等信息
- 替换
wgcf-profile.conf配置内容
token的输入:
- https://web--public--warp-team-api--coia-mfs4.code.run 获取token
- 生成私钥和公钥
- 通过API接口(https://api.cloudflareclient.com/v0a2158/reg) 申请配置
- 使用返回结果替换
wgcf-profile.conf配置内容
最终两种方法都是根据得到的配置信息替换wgcf-profile.conf,然后统一执行后置步骤。
选项1
直接使用wgcf-account.toml生成wgcf-profile.conf。
后置步骤
输出配置文件wgcf-profile.conf的内容,并使用文件内容调用qrencode程序生成二维码(所以扫码导入其实就是扫出的配置文件内容)。
验证
知道了原理,直接可以在Windows 下完成以上操作。下载对应的windows版本wgcf_2.2.21_windows_amd64.exe
1 2 3 4 5 6 7 8 9 10 11
| >wgcf.exe register 2024/01/26 20:46:05 ======================================= 2024/01/26 20:46:05 Device name : 0E6E15 2024/01/26 20:46:05 Device model : PC 2024/01/26 20:46:05 Device active : true 2024/01/26 20:46:05 Account type : free 2024/01/26 20:46:05 Role : child 2024/01/26 20:46:05 Premium data : 0.00 B 2024/01/26 20:46:05 Quota : 0.00 B 2024/01/26 20:46:05 ======================================= 2024/01/26 20:46:05 Successfully created Cloudflare Warp account
|
同时成功生成wgcf-account.toml账户文件。
1 2 3 4 5 6 7 8 9 10 11 12
| >wgcf.exe generate 2024/01/26 20:47:25 Using config file: wgcf-account.toml 2024/01/26 20:47:27 ======================================= 2024/01/26 20:47:27 Device name : 0E6E15 2024/01/26 20:47:27 Device model : PC 2024/01/26 20:47:27 Device active : true 2024/01/26 20:47:27 Account type : free 2024/01/26 20:47:27 Role : child 2024/01/26 20:47:27 Premium data : 0.00 B 2024/01/26 20:47:27 Quota : 0.00 B 2024/01/26 20:47:27 ======================================= 2024/01/26 20:47:27 Successfully generated WireGuard profile: wgcf-profile.conf
|
成功生成配置文件wgcf-profile.conf 注意这Quota是0 ,免费账户是没有流量额度的。
使用Warp+ Bot生成Warp+的Key, 然后替换wgcf-account.toml中的license_key。
随后执行更新wgcf.exe update --name forg20240126,并重新生成配置
1 2 3 4 5 6 7 8 9 10 11 12
| >wgcf.exe generate 2024/01/26 22:27:53 Using config file: wgcf-account.toml 2024/01/26 22:27:54 ======================================= 2024/01/26 22:27:54 Device name : forg20240126 2024/01/26 22:27:54 Device model : PC 2024/01/26 22:27:54 Device active : true 2024/01/26 22:27:54 Account type : limited 2024/01/26 22:27:54 Role : child 2024/01/26 22:27:54 Premium data : 21.85 PiB 2024/01/26 22:27:54 Quota : 21.85 PiB 2024/01/26 22:27:54 ======================================= 2024/01/26 22:27:54 Successfully generated WireGuard profile: wgcf-profile.conf
|
好了,找个二维码生成器把wgcf-profile.conf内容贴进去,生成二维码之后扫码导入,启动成功连接。
PS
脚本备份
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| #!/bin/sh
red(){ echo -e "\033[31m\033[01m$1\033[0m" }
green(){ echo -e "\033[32m\033[01m$1\033[0m" }
yellow(){ echo -e "\033[33m\033[01m$1\033[0m" }
rm -f wgcf-account.toml wgcf-profile.conf echo | ./wgcf register chmod +x wgcf-account.toml
clear yellow "请选择需要使用的 WARP 账户类型" echo "" echo -e " ${GREEN}1.${PLAIN} WARP 免费账户 ${YELLOW}(默认)${PLAIN}" echo -e " ${GREEN}2.${PLAIN} WARP+" echo -e " ${GREEN}3.${PLAIN} WARP Teams" echo "" read -p "请输入选项 [1-3]: " account_type if [[ $account_type == 2 ]]; then yellow "获取 CloudFlare WARP 账号密钥信息方法: " green "电脑: 下载并安装 CloudFlare WARP → 设置 → 偏好设置 → 账户 →复制密钥到脚本中" green "手机: 下载并安装 1.1.1.1 APP → 菜单 → 账户 → 复制密钥到脚本中" echo "" yellow "重要:请确保手机或电脑的 1.1.1.1 APP 的账户状态为WARP+!" echo "" read -rp "输入 WARP 账户许可证密钥 (26个字符): " warpkey until [[ $warpkey =~ ^[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}-[A-Z0-9a-z]{8}$ ]]; do red "WARP 账户许可证密钥格式输入错误,请重新输入!" read -rp "输入 WARP 账户许可证密钥 (26个字符): " warpkey done sed -i "s/license_key.*/license_key = \"$warpkey\"/g" wgcf-account.toml read -rp "请输入自定义设备名,如未输入则使用默认随机设备名: " devicename green "注册 WARP+ 账户中, 如下方显示: 400 Bad Request, 则使用 WARP 免费版账户" if [[ -n $devicename ]]; then ./wgcf update --name $(echo $devicename | sed s/[[:space:]]/_/g) else ./wgcf update fi ./wgcf generate elif [[ $account_type == 3 ]]; then ./wgcf generate chmod +x wgcf-profile.conf yellow "请选择申请 WARP Teams 账户方式" echo "" echo -e " ${GREEN}1.${PLAIN} 使用 Teams TOKEN ${YELLOW}(默认)${PLAIN}" echo -e " ${GREEN}2.${PLAIN} 使用提取出来的 xml 配置文件" echo "" read -p "请输入选项 [1-2]: " team_type
if [[ $team_type == 2 ]]; then yellow "获取 WARP Teams 账户 xml 配置文件方法:https://blog.misaka.rest/2023/02/11/wgcfteam-config/" yellow "请将提取到的 xml 配置文件上传至:https://gist.github.com" read -rp "请粘贴 WARP Teams 账户配置文件链接:" teamconfigurl if [[ -n $teamconfigurl ]]; then teams_config=$(curl -sSL "$teamconfigurl" | sed "s/\"/\"/g") private_key=$(expr "$teams_config" : '.*private_key">\([^<]*\).*') private_v6=$(expr "$teams_config" : '.*v6":"\([^[&]*\).*') sed -i "s#PrivateKey.*#PrivateKey = $private_key#g" wgcf-profile.conf; sed -i "s#Address.*128#Address = $private_v6/128#g" wgcf-profile.conf; else red "未提供WARP Teams 账户配置文件链接,脚本退出!" exit 1 fi else # 询问用户 WARP Teams 账户 TOKEN,并提示获取方式 yellow "请在此网站:https://web--public--warp-team-api--coia-mfs4.code.run/ 获取你的 WARP Teams 账户 TOKEN" read -rp "请输入 WARP Teams 账户的 TOKEN:" teams_token
if [[ -n $teams_token ]]; then # 生成 WireGuard 公私钥及 WARP 设备 ID 和 FCM Token private_key=$(wg genkey) public_key=$(wg pubkey <<< "$private_key") install_id=$(tr -dc 'A-Za-z0-9' </dev/urandom | head -c 22) fcm_token="${install_id}:APA91b$(tr -dc 'A-Za-z0-9' </dev/urandom | head -c 134)"
# 使用 CloudFlare API 申请 Teams 配置信息 team_result=$(curl --silent --location --tlsv1.3 --request POST 'https://api.cloudflareclient.com/v0a2158/reg' \ --header 'User-Agent: okhttp/3.12.1' \ --header 'CF-Client-Version: a-6.10-2158' \ --header 'Content-Type: application/json' \ --header "Cf-Access-Jwt-Assertion: ${team_token}" \ --data '{"key":"'${public_key}'","install_id":"'${install_id}'","fcm_token":"'${fcm_token}'","tos":"'$(date +"%Y-%m-%dT%H:%M:%S.%3NZ")'","model":"Linux","serial_number":"'${install_id}'","locale":"zh_CN"}')
# 提取 WARP IPv6 内网地址,用于替换 wgcf-profile.conf 文件中对应的内容 private_v6=$(expr "$team_result" : '.*"v6":[ ]*"\([^"]*\).*') sed -i "s#PrivateKey.*#PrivateKey = $private_key#g" wgcf-profile.conf; sed -i "s#Address.*128#Address = $private_v6/128#g" wgcf-profile.conf; fi fi else ./wgcf generate fi
clear green "WGCF 的 WireGuard 配置文件已生成成功!" yellow "下面是配置文件内容:" red "$(cat wgcf-profile.conf)" echo "" yellow "下面是配置文件分享二维码:" qrencode -t ansiutf8 < wgcf-profile.conf echo "" yellow "请在本地使用此方法:https://blog.misaka.rest/2023/03/12/cf-warp-yxip/ 优选可用的 Endpoint IP"
|
记录下有类似脚本会把Endpoint换成162.159.193.10:2408。
https://blog.misaka.rest/2023/03/12/cf-warp-yxip/
Endpoint 范围
1 2 3 4 5 6 7 8
| 162.159.192.1(1的取值范围0-254) 162.159.193.1(1的取值范围0-254) 162.159.195.1(1的取值范围0-254) 162.159.204.1(1的取值范围0-254) 188.114.96.1(1的取值范围0-254) 188.114.97.1(1的取值范围0-254) 188.114.98.1(1的取值范围0-254) 188.114.99.1(1的取值范围0-254)
|
可用端口:500、854、859、864、878、880、890、891、894、903、908、928、934、939、942、943、945、946、955、968、987、988、1002、1010、1014、1018、1070、1074、1180、1387、1701、1843、2371、2408、2506、3138、3476、3581、3854、4177、4198、4233、4500、5279、5956、7103、7152、7156、7281、7559、8319、8742、8854、8886