|
|
本帖最后由 yyuueexxiinngg 于 2019-9-29 02:20 编辑
Warp之旅可以告一段落了
脚本地址:
- https://github.com/yyuueexxiinngg/some-scripts/blob/master/cloudflare/warp2wireguard.js
复制代码
更新记录:
#1 2019.09.29 02:13
- 支持免费无限流量版Warp (注册时不填写aff). 之后可以通过aff升级到Warp Plus
刷aff脚本地址: https://www.52.ht/thread-590354-1-1.html
鉴于Warp在国内沦为电话线, 这里就不放太详细的一步步教程了
使用方法:
在WireGuard中选择手动添加来生成一对密钥, 获取方法: https://i.loli.net/2019/09/28/8QTJzYjlpbg4noF.jpg
把Public Key和Private Key分别填入脚本中运行
然后把生成的配置文件导入WireGuard就行, Allow ip可以自行根据需要修改
warp-conf.json中保存了口令供之后重新获取配置和查询流量使用
怎样获取剩余流量? 运行或者直接再次运行脚本
测试结果:
运行:

查询流量:

Windows版WireGuard测试:

iOS版WireGuard测试:

这里贴出中文版代码:
- const publicKey = "Public Key复制到这里";
- const privateKey = "Private Key复制到这里";
- const referrer = "Referrer ID复制到这里获取1G流量直接启用Warp+";
- if (!publicKey.endsWith("=") || !privateKey.endsWith("=")) {
- console.error("请正确填写密钥.");
- process.exit(1);
- }
- const https = require("https");
- const zlib = require("zlib");
- const fs = require("fs");
- const util = require("util");
- let warpConf = null;
- async function run() {
- let userData = {};
- if (fs.existsSync("./warp-conf.json")) {
- warpConf = JSON.parse(fs.readFileSync("./warp-conf.json").toString());
- } else {
- warpConf = {
- id: null,
- publicKey: publicKey, // WireGuard pubic key
- token: null, // Cloudflare access token
- isWarpPlusEnabled: null
- };
- }
- if (!warpConf.id) {
- console.log("未读取到保存信息, 正在注册新帐号中...");
- userData = await reg();
- console.log("注册成功:");
- console.log(util.inspect(userData, false, null, true));
- } else {
- console.log("正在获取用户信息...");
- const res = await getInfo(warpConf.id, warpConf.token);
- userData = res.result;
- if (
- !warpConf.isWarpPlusEnablsed && // If saved record indicate using free version of Cloudflare Warp
- userData.account &&
- (userData.account.premium_data || data.account.warp_plus)
- ) {
- warpConf.isWarpPlusEnabled = true;
- fs.writeFileSync("./warp-conf.json", JSON.stringify(warpConf));
- }
- console.log("成功获取用户信息:");
- if (process.argv[2] && process.argv[2] === "q") {
- if (warpConf.isWarpPlusEnabled) {
- console.log(
- "\x1b[36m%s\x1b[0m",
- "WARP PLUS剩余流量:",
- userData.account.quota / 1000000000,
- "GB"
- );
- } else {
- console.log(
- "\x1b[36m%s\x1b[0m",
- "您正在使用Cloudflare免费版Warp, 没有流量限制, 您可用自己的ID分享1.1.1.1来获取流量以升级到Warp Plus."
- );
- }
- process.exit(0);
- }
- console.log(util.inspect(userData, false, null, true));
- }
- const wireGuardConf = `
- [Interface]
- PrivateKey = ${privateKey}
- # PublicKey = ${publicKey}
- Address = ${userData.config.interface.addresses.v4}
- # Address = ${userData.config.interface.addresses.v6}
- DNS = 1.1.1.1
- [Peer]
- PublicKey = ${userData.config.peers[0].public_key}
- Endpoint = ${userData.config.peers[0].endpoint.v4}
- # Endpoint = ${userData.config.peers[0].endpoint.v6}
- # Endpoint = ${userData.config.peers[0].endpoint.host}
- AllowedIPs = 0.0.0.0/0
- `;
- console.log("Config: ");
- console.log(wireGuardConf);
- fs.writeFileSync("./wireguard-cloudflare-warp.conf", wireGuardConf);
- console.log(
- "Config saved, check wireguard-cloudflare-warp.conf in current dir."
- );
- if (warpConf.isWarpPlusEnabled) {
- console.log(
- "\x1b[36m%s\x1b[0m",
- "WARP PLUS剩余流量:",
- userData.account.quota / 1000000000,
- "GB"
- );
- } else {
- console.log(
- "\x1b[36m%s\x1b[0m",
- "您正在使用Cloudflare免费版Warp, 没有流量限制, 您可用自己的ID分享1.1.1.1来获取流量以升级到Warp Plus."
- );
- }
- }
- async function getInfo(id, token) {
- return new Promise(async resolve => {
- const result = await httpRequest({
- hostname: "api.cloudflareclient.com",
- port: 443,
- path: `/v0i1909221500/reg/${id}`,
- method: "GET",
- headers: {
- Accept: "*/*",
- Authorization: `Bearer ${token}`,
- Host: "api.cloudflareclient.com",
- "Accept-Encoding": "gzip",
- "Accept-Language": "Language",
- "User-Agent": "1.1.1.1/1909221500.1 CFNetwork/978.0.7 Darwin/18.7.0"
- }
- });
- if (result.success) {
- const data = result.payload;
- resolve(data);
- } else {
- console.error("获取用户信息失败.");
- process.exit(1);
- }
- });
- }
- async function reg() {
- return new Promise(async resolve => {
- const install_id = genString(11);
- const postData = {
- key: publicKey,
- install_id: install_id,
- fcm_token: `${install_id}:APA91b${genString(134)}`,
- referrer: /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(
- referrer
- )
- ? referrer
- : "",
- warp_enabled: true,
- tos: new Date().toISOString().replace("Z", "+08:00"),
- type: "Android",
- locale: "en_US"
- };
- const result = await httpRequest(
- {
- hostname: "api.cloudflareclient.com",
- port: 443,
- path: "/v0a745/reg",
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- Host: "api.cloudflareclient.com",
- Connection: "Keep-Alive",
- "Accept-Encoding": "gzip",
- "User-Agent": "okhttp/3.12.1"
- }
- },
- postData
- );
- if (result.success) {
- const data = result.payload;
- warpConf.id = data.id;
- warpConf.token = data.token;
- if (data.account && (data.account.premium_data || data.account.warp_plus))
- warpConf.isWarpPlusEnabled = true;
- fs.writeFileSync("./warp-conf.json", JSON.stringify(warpConf));
- resolve(data);
- } else {
- console.error("注册帐号失败.");
- process.exit(1);
- }
- });
- }
- function httpRequest(options, data = undefined) {
- return new Promise(resolve => {
- const bodyString = data ? JSON.stringify(data) : data;
- const req = https.request(options, res => {
- const gzip = zlib.createGunzip();
- const buffer = [];
- res.pipe(gzip);
- gzip
- .on("data", function(data) {
- buffer.push(data.toString());
- })
- .on("end", function() {
- const res = JSON.parse(buffer.join(""));
- resolve({ success: true, payload: res });
- })
- .on("error", function(e) {
- resolve({ success: false, payload: e });
- });
- });
- req.on("error", e => {
- resolve({ success: false, payload: e });
- });
- if (bodyString) req.write(bodyString);
- req.end();
- });
- }
- function genString(length) {
- // https://gist.github.com/6174/6062387#gistcomment-2651745
- return [...Array(length)]
- .map(i => (~~(Math.random() * 36)).toString(36))
- .join("");
- }
- run();
- // Original link: https://github.com/yyuueexxiinngg/some-scripts/blob/master/cloudflare/warp2wireguard.js
复制代码 |
|