Xray-core配合WARP实现国内流量分流

在上一篇blog的配置中,我对于国内流量是采用block的策略,但是这多多少少会带来一点不便,有时需要全局代理结果微信之类的就直接断网了。屏蔽回国流量的主要目的是为了隐藏自身,使xray从外部观察起来只是单纯的端口转发,而配合WARP就可以实现在损失一点点延迟的情况下顺利访问国内网站并隐藏自身。

为了使用WARP,我们首先使用wgcf这个非官方CLI来获取账号以及wireguard配置。

1
2
3
4
$ wget -O wgcf https://github.com/ViRb3/wgcf/releases/download/v2.2.18/wgcf\_2.2.18\_linux\_amd64
$ chmod +x wgcf
$ ./wgcf register
$ ./wgcf generate

以上命令逐条执行后,我们会在当前文件夹发现wgcf-account.toml和wgcf-profile.conf两个文件。其中wgcf-profile.conf文件中会有我们需要的private key以及public key。

接下来进行Endpoint IP优选,实测Endpoint IP优选与否对延迟与速率影响极大,我们在这里使用由MisakaNo制作的脚本进行优选:

$ wget -N https://gitlab.com/Misaka-blog/warp-script/-/raw/main/files/warp-yxip/warp-yxip.sh && bash warp-yxip.sh

执行后如下图

202306282355

根据提示进行选择即可得到优选IP。

然后是对xray-core配置文件config.json的修改。

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
//routing模块修改如下
"routing": {
"domainStrategy": "IPIfNonMatch",
"rules": \[
{
"type": "field",
"domain": \[
"geosite:category-ads-all"
\],
"outboundTag": "block"
},
{
"type": "field",
"domain": \[
"geosite:cn"
\],
"outboundTag": "warp-IPv4" //可以修改成自己想要的tag
},
{
"type": "field",
"ip": \[
"geoip:cn"
\],
"outboundTag": "warp-IPv4" //同上
}
\]
}

//outbound模块的修改如下
"outbounds": \[
{
"protocol": "freedom",
"tag": "direct"
},
{
"protocol": "blackhole",
"tag": "block"
},
{
"protocol": "wireguard",
"settings": {

"secretKey": "", //填入先前的private key
"address": \["172.16.0.2/32", "2606:4700:110:8c67:2b86:8c3b:6604:7932/128"\], //此处根据wgcf-profile.conf文件中的Address进行修改
"peers": \[
{
"publicKey": "", //填入先前的public key
"endpoint": "", //将优选的Endpoint IP填入即可,例:162.159.192.90:908
"allowedIPs": \[
"0.0.0.0/0",
"::/0"
\]
}
\],
"mtu": 1280
},
"tag": "warp-4"
},
{
"protocol": "freedom",
"settings": {
"domainStrategy": "UseIPv4"
},
"proxySettings": {
"tag": "warp-4"
},
"tag": "warp-IPv4" //前面的tag若修改了这里也要记得改
}
\]

之后,重启xray-core以应用配置。

$ docker restart xray

如此即可顺利配置WARP进行使用。接下来是刷WARP+流量的教学。

WARP与WARP+的区别,从官网我们可以了解到,+版本的速度等各方面会更好一点。

WARP+目前新人会有10Gb的流量,但是明显不是很够用。但WARP+目前仍然有邀请一个新用户来获得1Gb流量的政策,如此便产生了各类刷流量方法。

最简单的,在这个网站点击右上方的run,并根据提示输入wgcf-account.toml中的device_id即可开始刷流量。缺点是必须在前台运行,不过对于个人使用来说一般刷个1小时就够用很久了。(博主自测刷了大概一个小时刷了150Gb以上的流量)

然后是使用Github Action来刷流量的办法:

首先复制以下代码并保存为warp.py文件。

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
import urllib.request
import json
import datetime
import random
import string
import time
import os
import sys
os.system("title WARP-PLUS-CLOUDFLARE By ALIILAPRO")
os.system('cls' if os.name == 'nt' else 'clear')
print('Getting WARP+ Traffic on Github Actions')
referrer = os.environ\["DEVICEID"\]
def genString(stringLength):
try:
letters = string.ascii\_letters + string.digits
return ''.join(random.choice(letters) for i in range(stringLength))
except Exception as error:
print(error)
def digitString(stringLength):
try:
digit = string.digits
return ''.join((random.choice(digit) for i in range(stringLength)))
except Exception as error:
print(error)
url = f'https://api.cloudflareclient.com/v0a{digitString(3)}/reg'
def run():
try:
install\_id = genString(22)
body = {"key": "{}=".format(genString(43)),
"install\_id": install\_id,
"fcm\_token": "{}:APA91b{}".format(install\_id, genString(134)),
"referrer": referrer,
"warp\_enabled": False,
"tos": datetime.datetime.now().isoformat()\[:-3\] + "+02:00",
"type": "Android",
"locale": "es\_ES"}
data = json.dumps(body).encode('utf8')
headers = {'Content-Type': 'application/json; charset=UTF-8',
'Host': 'api.cloudflareclient.com',
'Connection': 'Keep-Alive',
'Accept-Encoding': 'gzip',
'User-Agent': 'okhttp/3.12.1'
}
req = urllib.request.Request(url, data, headers)
response = urllib.request.urlopen(req)
status\_code = response.getcode()
return status\_code
except Exception as error:
print(error)

g = 0
b = 0
while True:
result = run()
if result == 200:
g = g + 1
os.system('cls' if os.name == 'nt' else 'clear')
print("")
print("Getting WARP+ Traffic")
print("")
animation = \["\[■□□□□□□□□□\] 10%","\[■■□□□□□□□□\] 20%", "\[■■■□□□□□□□\] 30%", "\[■■■■□□□□□□\] 40%", "\[■■■■■□□□□□\] 50%", "\[■■■■■■□□□□\] 60%", "\[■■■■■■■□□□\] 70%", "\[■■■■■■■■□□\] 80%", "\[■■■■■■■■■□\] 90%", "\[■■■■■■■■■■\] 100%"\]
for i in range(len(animation)):
time.sleep(0.5)
sys.stdout.write("\\r\[+\] Preparing... " + animation\[i % len(animation)\])
sys.stdout.flush()
print(f"\\n\[-\] WORK ON ID: {referrer}")
print(f"\[:)\] {g} GB has been successfully added to your account.")
print(f"\[#\] Total: {g} Good {b} Bad")
print("\[\*\] After 18 seconds, a new request will be sent.")
time.sleep(18)
else:
b = b + 1
os.system('cls' if os.name == 'nt' else 'clear')
print("")
print("Getting WARP+ Traffic")
print("")
print("\[:(\] Error when connecting to server.")
print(f"\[#\] Total: {g} Good {b} Bad")

在自己的GitHub中新建一个repository,将warp.py上传至该repository中。

进入该repository的action界面,选择set up a workflow yourself,复制黏贴以下内容:

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
name: 'Getting WARP+ Traffic'

on:
workflow\_dispatch:
push:
branches:
- main
schedule:
- cron: '33 8 \* \* \*'

jobs:
auto\_getting\_traffic:
runs-on: ubuntu-latest
steps:
- name: 'Checking'
uses: actions/checkout@v2

- name: 'Setting Python'
uses: actions/setup-python@v1
with:
python-version: '3.x'

- name: 'Getting WARP+ Traffic'
env:
DEVICEID: ${{ secrets.DEVICEID }}
run: python warp.py

点击右方绿色按钮保存。

转到该repository的setting,设置一个secret,名称为DEVICEID,内容为你的wgcf-account.toml中的device_id,保存。

回到action页面,选择Getting WARP+ Traffic,并run workflow即可开始刷流量。

参考:

https://ednovas.xyz/2021/10/05/warp+/#F-amp-Q

https://github.com/ViRb3/wgcf

https://blog.misaka.rest/2023/03/12/cf-warp-yxip/

https://xtls.github.io/document/level-2/warp.html#%E5%AE%A2%E6%88%B7%E7%AB%AF%E4%BD%BF%E7%94%A8-warp-%E9%93%BE%E5%BC%8F%E4%BB%A3%E7%90%86


Xray-core配合WARP实现国内流量分流
https://nekonya.one/2023/06/29/xray-core配合warp实现国内流量分流/
作者
Guawazi233
发布于
2023年6月29日
许可协议