X Tutup
Skip to content

Commit f350cbb

Browse files
authored
Add files via upload
1 parent e1deb81 commit f350cbb

File tree

2 files changed

+152
-0
lines changed

2 files changed

+152
-0
lines changed

README.rst

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
python-proxy
2+
===========
3+
4+
HTTP/Socks5/Shadowsocks Asynchronous Tunnel Proxy implemented in Python 3.6 asyncio.
5+
6+
Python 3.6
7+
-----------
8+
9+
*Python 3.5* added new syntax *async def* and *await* to make asyncio programming easier. *Python 3.6* added new syntax *formatted string literals*. This utility is to demonstrate these new syntax and is also fully ready for production usage.
10+
11+
Features
12+
-----------
13+
14+
- Automatically detect incoming protocol: HTTP/Socks5/Shadowsocks.
15+
- Specify remote servers for outcoming protocol.
16+
- Unix path support for communicating locally.
17+
- Basic authentication method for HTTP/Socks5/Shadowsocks.
18+
- Regex pattern file support for redirecting/blocking by hostname.
19+
- SSL connection support to prevent Man-In-The-Middle attack.
20+
- Many ciphers support to keep communication securely. (chacha20, salsa20, aes-256-cfb, etc)
21+
- Basic statistics for bandwidth and total traffic by client/hostname.
22+
- PAC support for automatically javascript configuration.
23+
24+
Usage
25+
-----------
26+
27+
$ pproxy -h
28+
usage: pproxy [-h] [-i LISTEN] [-r RSERVER] [-b BLOCK] [-v]
29+
[--ssl SSLFILE] [--pac PAC] [--version]
30+
31+
Proxy server that can tunnel among remote servers by regex rules. Supported
32+
protocols: http,socks,shadowsocks
33+
34+
optional arguments:
35+
-h, --help show this help message and exit
36+
-i LISTEN proxy server setting uri (default: http+socks://:8080/)
37+
-r RSERVER remote server setting uri (default: direct)
38+
-b BLOCK block regex rules
39+
-v print verbose output
40+
--ssl SSLFILE certfile[,keyfile] if server listen in ssl mode
41+
--pac PAC http pac file path
42+
--version show program's version number and exit
43+
44+
Online help: <https://github.com/qwj/python-proxy>
45+
46+
Uri Syntax
47+
-----------
48+
49+
{scheme}://[{cipher}@]{netloc}[?{rules}][#{auth}]
50+
51+
- scheme
52+
Currently supported scheme: http, socks, ss, ssl, secure. You can use + to add multiple protocols together.
53+
http - http protocol
54+
socks - socks5 protocol
55+
ss - shadowsocks protocol
56+
ssl - communicate in (unsecured) ssl
57+
secure - comnunicate in (secured) ssl
58+
Valid schemes are: http://, http+socks://, http+ssl://, ss+secure://
59+
Invalid schemes are: ssl://, secure://
60+
- cipher
61+
Cipher is consisted by cipher name, colon ':' and cipher key.
62+
Full cipher list: table, rc4, rc4-md5, chacha20, salsa20, aes-128-cfb, aes-192-cfb, aes-256-cfb, bf-cfb, cast5-fb, des-cfb
63+
- netloc
64+
It can be "hostname:port" or "/unix_path". If the hostname is empty, server will listen on all interfaces.
65+
- rules
66+
The filename that contains regex rules
67+
- auth
68+
The username, colon ':', and the password
69+
70+
Examples
71+
-----------
72+
73+
We can define file "rules" as follow:
74+
75+
#google domains
76+
(?:.+\.)?google.*\.com
77+
(?:.+\.)?gstatic\.com
78+
(?:.+\.)?gmail\.com
79+
(?:.+\.)?ntp\.org
80+
(?:.+\.)?glpals\.com
81+
(?:.+\.)?akamai.*\.net
82+
(?:.+\.)?ggpht\.com
83+
(?:.+\.)?android\.com
84+
(?:.+\.)?gvt1\.com
85+
(?:.+\.)?youtube.*\.com
86+
(?:.+\.)?ytimg\.com
87+
(?:.+\.)?goo\.gl
88+
(?:.+\.)?youtu\.be
89+
(?:.+\.)?google\..+
90+
91+
Then start the pproxy
92+
93+
pproxy -i http+socks://:8080 -r http://aa.bb.cc.dd:8080?rules -v
94+
95+
With these parameters, this utility will serve incoming traffic by either http/socks5 protocol, redirect all google traffic to http proxy aa.bb.cc.dd:8080, and visit all other traffic locally.
96+
97+
To bridge two servers, add cipher key to ensure data can't be intercepted. First, run pproxy locally
98+
99+
pproxy -i ss://:8888 -r ss://chacha20:cipher_key@aa.bb.cc.dd:12345 -v
100+
101+
Next, run pproxy.py remotely on server "aa.bb.cc.dd"
102+
103+
pproxy -i ss://chacha20:cipher_key@:12345
104+
105+
By doing this, the traffic between local and aa.bb.cc.dd is encrypted by stream cipher Chacha20 with key "This is a cipher key". If target hostname is not in "rules", traffic will go through locally. Otherwise, traffic will go through the remote server by encryption.
106+

setup.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from setuptools import setup
2+
import os, io, re
3+
4+
def read(*names, **kwargs):
5+
with io.open(
6+
os.path.join(os.path.dirname(__file__), *names),
7+
encoding=kwargs.get("encoding", "utf8")
8+
) as fp:
9+
return fp.read()
10+
11+
def find_version(*file_paths):
12+
version_file = read(*file_paths)
13+
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
14+
version_file, re.M)
15+
if version_match:
16+
return version_match.group(1)
17+
raise RuntimeError("Unable to find version string.")
18+
19+
setup(
20+
name='pproxy',
21+
version=find_version('pproxy', '__init__.py'),
22+
description='Proxy server that can tunnel among remote servers by regex rules.',
23+
long_description=read('README.rst'),
24+
url='https://github.com/qwj/python-proxy',
25+
author='Qian Wenjie',
26+
author_email='qianwenjie@gmail.com',
27+
license='MIT',
28+
classifiers=[
29+
'Development Status :: 5 - Production/Stable',
30+
'Environment :: Console',
31+
'Intended Audience :: Developers',
32+
'Natural Language :: English',
33+
'Topic :: Software Development :: Build Tools',
34+
'License :: OSI Approved :: MIT License',
35+
'Programming Language :: Python :: 3',
36+
'Programming Language :: Python :: 3.6',
37+
],
38+
keywords='proxy socks http shadowsocks cipher ssl',
39+
packages=['pproxy'],
40+
install_requires=['pycryptodome'],
41+
entry_points={
42+
'console_scripts': [
43+
'pproxy=pproxy:main',
44+
],
45+
},
46+
)

0 commit comments

Comments
 (0)
X Tutup