Skip to content

Commit 61811d0

Browse files
ljm625Jiaming Li
authored and
Jiaming Li
committed
Initial commit
0 parents  commit 61811d0

17 files changed

+654
-0
lines changed

.gitignore

+202
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
2+
### Python template
3+
# Byte-compiled / optimized / DLL files
4+
__pycache__/
5+
*.py[cod]
6+
*$py.class
7+
8+
# C extensions
9+
*.so
10+
11+
# Distribution / packaging
12+
.Python
13+
env/
14+
build/
15+
develop-eggs/
16+
dist/
17+
downloads/
18+
eggs/
19+
.eggs/
20+
lib/
21+
lib64/
22+
parts/
23+
sdist/
24+
var/
25+
wheels/
26+
*.egg-info/
27+
.installed.cfg
28+
*.egg
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+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*,cover
49+
.hypothesis/
50+
51+
# Translations
52+
*.mo
53+
*.pot
54+
55+
# Django stuff:
56+
*.log
57+
local_settings.py
58+
59+
# Flask stuff:
60+
instance/
61+
.webassets-cache
62+
63+
# Scrapy stuff:
64+
.scrapy
65+
66+
# Sphinx documentation
67+
docs/_build/
68+
69+
# PyBuilder
70+
target/
71+
72+
# Jupyter Notebook
73+
.ipynb_checkpoints
74+
75+
# pyenv
76+
.python-version
77+
78+
# celery beat schedule file
79+
celerybeat-schedule
80+
81+
# SageMath parsed files
82+
*.sage.py
83+
84+
# dotenv
85+
.env
86+
87+
# virtualenv
88+
.venv
89+
venv/
90+
ENV/
91+
92+
# Spyder project settings
93+
.spyderproject
94+
95+
# Rope project settings
96+
.ropeproject
97+
### JetBrains template
98+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
99+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
100+
101+
# User-specific stuff:
102+
.idea/**/workspace.xml
103+
.idea/**/tasks.xml
104+
.idea/dictionaries
105+
106+
# Sensitive or high-churn files:
107+
.idea/**/dataSources/
108+
.idea/**/dataSources.ids
109+
.idea/**/dataSources.xml
110+
.idea/**/dataSources.local.xml
111+
.idea/**/sqlDataSources.xml
112+
.idea/**/dynamic.xml
113+
.idea/**/uiDesigner.xml
114+
115+
# Gradle:
116+
.idea/**/gradle.xml
117+
.idea/**/libraries
118+
119+
# Mongo Explorer plugin:
120+
.idea/**/mongoSettings.xml
121+
122+
## File-based project format:
123+
*.iws
124+
125+
## Plugin-specific files:
126+
127+
# IntelliJ
128+
/out/
129+
130+
# mpeltonen/sbt-idea plugin
131+
.idea_modules/
132+
133+
# JIRA plugin
134+
atlassian-ide-plugin.xml
135+
136+
# Crashlytics plugin (for Android Studio and IntelliJ)
137+
com_crashlytics_export_strings.xml
138+
crashlytics.properties
139+
crashlytics-build.properties
140+
fabric.properties
141+
### Linux template
142+
*~
143+
144+
# temporary files which can be created if a process still has a handle open of a deleted file
145+
.fuse_hidden*
146+
147+
# KDE directory preferences
148+
.directory
149+
150+
# Linux trash folder which might appear on any partition or disk
151+
.Trash-*
152+
153+
# .nfs files are created when an open file is removed but is still being accessed
154+
.nfs*
155+
### macOS template
156+
*.DS_Store
157+
.AppleDouble
158+
.LSOverride
159+
160+
# Icon must end with two \r
161+
Icon
162+
163+
164+
# Thumbnails
165+
._*
166+
167+
# Files that might appear in the root of a volume
168+
.DocumentRevisions-V100
169+
.fseventsd
170+
.Spotlight-V100
171+
.TemporaryItems
172+
.Trashes
173+
.VolumeIcon.icns
174+
.com.apple.timemachine.donotpresent
175+
176+
# Directories potentially created on remote AFP share
177+
.AppleDB
178+
.AppleDesktop
179+
Network Trash Folder
180+
Temporary Items
181+
.apdisk
182+
### Windows template
183+
# Windows thumbnail cache files
184+
Thumbs.db
185+
ehthumbs.db
186+
ehthumbs_vista.db
187+
188+
# Folder config file
189+
Desktop.ini
190+
191+
# Recycle Bin used on file shares
192+
$RECYCLE.BIN/
193+
194+
# Windows Installer files
195+
*.cab
196+
*.msi
197+
*.msm
198+
*.msp
199+
200+
# Windows shortcuts
201+
*.lnk
202+

Dockerfile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
FROM ubuntu:14.04
2+
MAINTAINER Jiaming Li <ljm625@gmail.com>
3+
ENV NGINX_VERSION 1.9.11-1~jessie
4+
RUN apt-get update
5+
RUN apt-get install -y ca-certificates nginx gettext-base vim supervisor python-pip
6+
# forward request and error logs to docker log collector
7+
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
8+
&& ln -sf /dev/stderr /var/log/nginx/error.log
9+
# Make NGINX run on the foreground
10+
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
11+
# Copy the modified Nginx conf
12+
COPY nginx.conf /etc/nginx/conf.d/
13+
# Install Supervisord
14+
RUN rm -rf /var/lib/apt/lists/*
15+
# Custom Supervisord config
16+
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
17+
COPY nginx.conf /etc/nginx/conf.d/
18+
COPY ./ /app
19+
RUN pip install -r /app/requirements.txt
20+
EXPOSE 9000 9090
21+
WORKDIR /app
22+
RUN export LANG=C.UTF-8
23+
CMD ["/usr/bin/supervisord"]

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# 解除网易云音乐海外限制
2+
docker run -p 9000:9000 -p 9090:9090 -m 256m -d ljm625/unblock-netease
3+
4+
然后设置你的设备pac为 http://你的ip:9000/proxy.pac 即可
5+
6+
这个PAC只会代理网易..可以自己修改config.yaml更改匹配规则&PAC生成规则
7+
8+
文档施工中..

components/__init__.py

Whitespace-only changes.

components/pac_generator.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import requests
2+
import yaml
3+
from jinja2 import Environment
4+
from jinja2 import FileSystemLoader
5+
6+
7+
class PacGenerator(object):
8+
def __init__(self,config):
9+
self.env = Environment(loader=FileSystemLoader('template'))
10+
def yaml_loader(file):
11+
with open(file) as f:
12+
return yaml.load(f)
13+
self.config=yaml_loader(config)
14+
15+
16+
def get_ip(self):
17+
resp=requests.get("http://icanhazip.com/",timeout=2)
18+
try:
19+
if resp.status_code>300:
20+
return "127.0.0.1"
21+
else:
22+
return str(resp.text).strip()
23+
except:
24+
return "127.0.0.1"
25+
26+
def build_pac(self):
27+
info={}
28+
info['proxy_domain']=self.config['proxy_domain']
29+
if self.config.get("proxy_ip"):
30+
info['proxy_ip']=self.config.get("proxy_ip")
31+
else:
32+
info['proxy_ip']=self.get_ip()
33+
info['proxy_port']=self.config.get("proxy_port")
34+
template = self.env.get_template("proxy.pac")
35+
self.file_writer(template.render(info=info))
36+
37+
def file_writer(self,data):
38+
with open("pac/proxy.pac",'w') as file:
39+
file.write(data)

components/proxy_checker.py

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import requests
2+
import yaml
3+
4+
5+
class ProxyChecker(object):
6+
best_proxy=None
7+
instance=None
8+
def __init__(self,proxy_list,check_url,timeout=2):
9+
self.proxy_list=proxy_list
10+
self.check_url=check_url
11+
self.timeout=timeout
12+
13+
@classmethod
14+
def get_instance(cls,proxy_list=None):
15+
def yaml_loader(file):
16+
with open(file) as f:
17+
return yaml.load(f)
18+
19+
if cls.instance:
20+
return cls.instance
21+
elif not proxy_list:
22+
return None
23+
else:
24+
config=yaml_loader('config.yaml')
25+
check_url=config.get('validate_url')
26+
timeout=config.get('timeout')
27+
if check_url and timeout:
28+
cls.instance=cls(proxy_list=proxy_list,check_url=check_url,timeout=timeout)
29+
return cls.instance
30+
else:
31+
raise Exception("ERROR : The Config URL is missing")
32+
33+
def validate_proxy(self,proxy):
34+
def build_proxy():
35+
return {"http": "http://{}:{}".format(proxy[0],proxy[1]) }
36+
try:
37+
resp=requests.get(self.check_url,proxies=build_proxy(),timeout=self.timeout)
38+
if resp.status_code<300 and resp.text=='true':
39+
# TODO : The netease validate link always return false whether it's mainland or not
40+
return resp.elapsed.total_seconds()*1000
41+
return None
42+
except Exception as e:
43+
return None
44+
45+
def get_best_proxy(self):
46+
best=None
47+
min_latency=None
48+
for proxy in self.proxy_list:
49+
result = self.validate_proxy(proxy)
50+
if result:
51+
if not best:
52+
best=proxy
53+
min_latency=result
54+
else:
55+
if result<min_latency:
56+
best=proxy
57+
min_latency=result
58+
if not best:
59+
raise AttributeError("ERROR : No available servers! ")
60+
self.best_proxy=best
61+
62+
def get_proxy(self,refresh=False):
63+
if self.best_proxy and not refresh:
64+
return self.best_proxy
65+
else:
66+
self.get_best_proxy()
67+
return self.best_proxy
68+
69+
def update_list(self,list):
70+
self.proxy_list=list

0 commit comments

Comments
 (0)