Skip to content

Commit f2e5d13

Browse files
committed
002-V2rayPool
1 parent 22069f3 commit f2e5d13

34 files changed

+2874
-1
lines changed

002-V2rayPool/.gitignore

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/

002-V2rayPool/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# v2ray节点代理池
2+
学习python爬虫过程中,我们需要一些代理。而本项目则是通过收集网上公开的节点,来实现自己的代理请求的过程!
3+
4+
## v2ray是什么?如何使用?
5+
- [v2ray官方指导](https://www.v2ray.com/index.html)
6+
7+
- [v2ray wiki](https://zh.wikipedia.org/wiki/V2Ray)
8+
9+
## v2ray客户端推荐
10+
- [window:v2rayN](https://github.com/2dust/v2rayN/releases)
11+
- [macOS:V2rayU](https://github.com/yanue/V2rayU/releases)
12+
- [android:v2rayNG](https://github.com/2dust/v2rayNG/releases)
13+
- ios推荐Shadowrocket(俗称小火箭,注意不是shadowrocket VPN),但需要付费的,可以通过找"美区apple id共享2021小火箭",找共享的账号下载软件,但是会有风险,请一定要注意。
14+
15+
## v2ray服务端推荐
16+
有些应用场景会需要到用到专用的ip代理,如Tik Tok、亚马逊和Facebook等。这是,我们通过购买国外的服务器或者vps来搭建代理服务器,从而实现专有ip代理。
17+
18+
推荐使用[x-ui](https://github.com/vaxilu/x-ui) 进行非常简单的"一键式"搭建开源框架。
19+
20+
#本项目主要知识点
21+
学习本项目需要先了解代理原理,以及v2ray实现的原理。
22+
23+
## 实现思路
24+
![实现思路图](./doc/v2ray.jpg)
25+
26+
## v2ray内核使用
27+
我们找的是v2ray节点,所以这些协议只能运行在v2ray特有程序中。因此,我们要找[v2ray内核](https://github.com/v2ray/v2ray-core/releases) 。 这里就以macOS系统举例说明:
28+
1. 下载[v2ray-core-v4.31.0](https://github.com/v2fly/v2ray-core/releases/download/v4.31.0/v2ray-macos-64.zip)
29+
2. 配置解压目录的路径:
30+
```python
31+
Config.set_v2ray_core_path('xxx/Downloads/v2ray-macos-64')
32+
```
33+
3. 查看是否能正常启动:
34+
```python
35+
client.Creator().v2ray_start('ss://[email protected]:43893#github.com/freefq%20-%20%E7%BD%97%E9%A9%AC%E5%B0%BC%E4%BA%9A%20%2041')
36+
```
37+
38+
## 2021-09-23检测可用测试节点:
39+
```shell
40+
#,2.59.214.204,俄罗斯莫斯科
41+
ss://[email protected]:33992#github.com/freefq%20-%20%E5%8D%A2%E6%A3%AE%E5%A0%A1%20%2051,185.153.151.86,卢森堡
42+
trojan://[email protected]:8443#github.com/freefq%20-%20%E4%B9%8C%E5%85%8B%E5%85%B0%20%2052
43+
# </p>,8.37.43.232,日本东京 Level3
44+
vmess://eyJ2IjogIjIiLCAicHMiOiAiZ2l0aHViLmNvbS9mcmVlZnEgLSBcdTY1ZTVcdTY3MmNcdTRlMWNcdTRlYWNBbWF6b25cdTY1NzBcdTYzNmVcdTRlMmRcdTVmYzMgNTQiLCAiYWRkIjogImFmMDEudXdvcmsubW9iaSIsICJwb3J0IjogIjgwIiwgImlkIjogIjAwMDAwMDAwLTAwMDAtMDAwMC0wMDAwLTAwMDAwMDAwMDAwMSIsICJhaWQiOiAiNjQiLCAibmV0IjogInRjcCIsICJ0eXBlIjogIm5vbmUiLCAiaG9zdCI6ICIiLCAicGF0aCI6ICIiLCAidGxzIjogIm5vbmUifQ==
45+
#,132.226.169.93,荷兰阿姆斯特丹
46+
vmess://ew0KICAidiI6ICIyIiwNCiAgInBzIjogIkBTU1JTVUItVjI3LeS7mOi0ueaOqOiNkDpzdW8ueXQvc3Nyc3ViIiwNCiAgImFkZCI6ICIxMzIuMjI2LjE2OS45MyIsDQogICJwb3J0IjogIjMzMjU0IiwNCiAgImlkIjogIjA0NTMxNTRiLWRiNTEtNGE2Ni04ZjdjLTA4ODc4NzhjYjlhMyIsDQogICJhaWQiOiAiMCIsDQogICJzY3kiOiAiYXV0byIsDQogICJuZXQiOiAidGNwIiwNCiAgInR5cGUiOiAibm9uZSIsDQogICJob3N0IjogIjEzMi4yMjYuMTY5LjkzIiwNCiAgInBhdGgiOiAiIiwNCiAgInRscyI6ICIiLA0KICAic25pIjogIiINCn0=
47+
#,185.22.153.187,俄罗斯莫斯科
48+
vmess://ew0KICAidiI6ICIyIiwNCiAgInBzIjogImh0dHBzOi8vZ2l0LmlvL3Y5OTk5IOiOq+aWr+enkWciLA0KICAiYWRkIjogIjE4NS4yMi4xNTMuMTg3IiwNCiAgInBvcnQiOiAiNDM1NDYiLA0KICAiaWQiOiAiMjViOGI4YTYtMTdiOC0xMWVjLWJiNTAtMGFiM2VhMTM0ZDA2IiwNCiAgImFpZCI6ICIwIiwNCiAgIm5ldCI6ICJ0Y3AiLA0KICAidHlwZSI6ICJub25lIiwNCiAgImhvc3QiOiAiIiwNCiAgInBhdGgiOiAiIiwNCiAgInRscyI6ICIiLA0KICAic25pIjogIiINCn0=
49+
```
50+
51+
> 如上面不可用,更多请留意:[db/_db-checked.txt](./db/_db-checked.txt)
52+
53+
注意:本程序虽可跨平台,但因博主能力有限,无法在更多系统上去尝试和改进,望谅解!
54+
55+
-------
56+
57+
如有可用节点增加,请推荐给博主吧:[email protected]

002-V2rayPool/base/net_proxy.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
"""
4+
@Description: 网络代理请求的基类
5+
@Date :2021/09/15
6+
@Author :xhunmon
7+
8+
"""
9+
10+
import requests
11+
from my_fake_useragent import UserAgent
12+
13+
14+
class Net(object):
15+
"""
16+
基类,封装常用接口
17+
"""
18+
TIMEOUT = 8
19+
20+
def __init__(self, timeout=8):
21+
Net.TIMEOUT = timeout
22+
self._ua = UserAgent()
23+
self._agent = self._ua.random() # 随机生成的agent
24+
self.USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:65.0) Gecko/20100101 Firefox/65.0"
25+
self._headers = {"user-agent": self.USER_AGENT, 'Connection': 'close'}
26+
# determine
27+
self._proxy = '127.0.0.1:1080'
28+
self._proxies_en = {
29+
'http': 'socks5h://' + self._proxy,
30+
'https': 'socks5h://' + self._proxy,
31+
}
32+
self._proxies_zh = {
33+
'http': 'socks5://' + self._proxy,
34+
'https': 'socks5://' + self._proxy,
35+
}
36+
37+
def get_header(self, headers, key):
38+
key_lower = key.lower()
39+
headers_lower = {k.lower(): v for k, v in headers.items()}
40+
if (key_lower in headers_lower):
41+
return headers_lower[key_lower]
42+
else:
43+
return ''
44+
45+
def get_urls(self) -> []:
46+
"""需子类实现"""
47+
pass
48+
49+
def request(self, url, allow_redirects=False, verify=False, timeout=TIMEOUT):
50+
"""普通请求"""
51+
return self.__request(url, allow_redirects=allow_redirects, verify=verify, timeout=timeout)
52+
53+
def request_en(self, url, allow_redirects=False, verify=False, timeout=TIMEOUT):
54+
"""国外网站请求,需要开代理"""
55+
return self.__request(url, allow_redirects=allow_redirects, verify=verify, proxies=self._proxies_en,
56+
timeout=timeout)
57+
58+
def request_zh(self, url, allow_redirects=False, verify=False, timeout=TIMEOUT):
59+
"""国内网站请求,需要开代理"""
60+
return self.__request(url, allow_redirects=allow_redirects, verify=verify, proxies=self._proxies_zh,
61+
timeout=timeout)
62+
63+
def __request(self, url, allow_redirects=False, verify=False, proxies=None, timeout=TIMEOUT):
64+
"""最终的请求实现"""
65+
requests.packages.urllib3.disable_warnings()
66+
if proxies:
67+
return requests.get(url=url, headers=self._headers, allow_redirects=allow_redirects, verify=verify,
68+
proxies=proxies, timeout=timeout)
69+
else:
70+
return requests.get(url=url, headers=self._headers, allow_redirects=allow_redirects, verify=verify,
71+
timeout=timeout)

0 commit comments

Comments
 (0)