python-socks 2.4.0__py3-none-any.whl → 2.4.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_socks/_protocols/socks5.py +3 -0
- python_socks/_version.py +1 -1
- python_socks-2.4.2.dist-info/METADATA +276 -0
- {python_socks-2.4.0.dist-info → python_socks-2.4.2.dist-info}/RECORD +7 -7
- python_socks-2.4.0.dist-info/METADATA +0 -23
- {python_socks-2.4.0.dist-info → python_socks-2.4.2.dist-info}/LICENSE.txt +0 -0
- {python_socks-2.4.0.dist-info → python_socks-2.4.2.dist-info}/WHEEL +0 -0
- {python_socks-2.4.0.dist-info → python_socks-2.4.2.dist-info}/top_level.txt +0 -0
|
@@ -190,6 +190,9 @@ class ConnectReply:
|
|
|
190
190
|
|
|
191
191
|
@classmethod
|
|
192
192
|
def loads(cls, data: bytes) -> 'ConnectReply':
|
|
193
|
+
if not data:
|
|
194
|
+
raise ReplyError('Empty connect reply')
|
|
195
|
+
|
|
193
196
|
ver = data[0]
|
|
194
197
|
if ver != SOCKS_VER: # pragma: no cover
|
|
195
198
|
raise ReplyError(f'Unexpected SOCKS version number: {ver:#02X}')
|
python_socks/_version.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
__title__ = 'python-socks'
|
|
2
|
-
__version__ = '2.4.
|
|
2
|
+
__version__ = '2.4.2'
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: python-socks
|
|
3
|
+
Version: 2.4.2
|
|
4
|
+
Summary: Core proxy (SOCKS4, SOCKS5, HTTP tunneling) functionality for Python
|
|
5
|
+
Home-page: https://github.com/romis2012/python-socks
|
|
6
|
+
Author: Roman Snegirev
|
|
7
|
+
Author-email: snegiryev@gmail.com
|
|
8
|
+
License: Apache 2
|
|
9
|
+
Keywords: socks socks5 socks4 http proxy asyncio trio curio anyio
|
|
10
|
+
Platform: UNKNOWN
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE.txt
|
|
13
|
+
Provides-Extra: anyio
|
|
14
|
+
Requires-Dist: anyio (<4.0.0,>=3.3.4) ; extra == 'anyio'
|
|
15
|
+
Provides-Extra: asyncio
|
|
16
|
+
Requires-Dist: async-timeout (>=3.0.1) ; extra == 'asyncio'
|
|
17
|
+
Provides-Extra: curio
|
|
18
|
+
Requires-Dist: curio (>=1.4) ; extra == 'curio'
|
|
19
|
+
Provides-Extra: trio
|
|
20
|
+
Requires-Dist: trio (>=0.16.0) ; extra == 'trio'
|
|
21
|
+
|
|
22
|
+
## python-socks
|
|
23
|
+
|
|
24
|
+
[](https://travis-ci.com/github/romis2012/python-socks)
|
|
25
|
+
[](https://coveralls.io/github/romis2012/python-socks?branch=master)
|
|
26
|
+
[](https://badge.fury.io/py/python-socks)
|
|
27
|
+
<!--
|
|
28
|
+
[](https://pepy.tech/project/python-socks)
|
|
29
|
+
-->
|
|
30
|
+
|
|
31
|
+
The `python-socks` package provides a core proxy client functionality for Python.
|
|
32
|
+
Supports SOCKS4(a), SOCKS5(h), HTTP (tunneling) proxy and provides sync and async (asyncio, trio, curio, anyio) APIs.
|
|
33
|
+
You probably don't need to use `python-socks` directly.
|
|
34
|
+
It is used internally by
|
|
35
|
+
[aiohttp-socks](https://github.com/romis2012/aiohttp-socks) and [httpx-socks](https://github.com/romis2012/httpx-socks) packages.
|
|
36
|
+
|
|
37
|
+
## Requirements
|
|
38
|
+
- Python >= 3.6
|
|
39
|
+
- async-timeout >= 3.0.1 (optional)
|
|
40
|
+
- trio >= 0.16.0 (optional)
|
|
41
|
+
- curio >= 1.4 (optional)
|
|
42
|
+
- anyio >= 3.3.4 (optional)
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
only sync proxy support:
|
|
47
|
+
```
|
|
48
|
+
pip install python-socks
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
to include optional asyncio support:
|
|
52
|
+
```
|
|
53
|
+
pip install python-socks[asyncio]
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
to include optional trio support:
|
|
57
|
+
```
|
|
58
|
+
pip install python-socks[trio]
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
to include optional curio support:
|
|
62
|
+
```
|
|
63
|
+
pip install python-socks[curio]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
to include optional anyio support:
|
|
67
|
+
```
|
|
68
|
+
pip install python-socks[anyio]
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Simple usage
|
|
72
|
+
We are making secure HTTP GET request via SOCKS5 proxy
|
|
73
|
+
|
|
74
|
+
#### Sync
|
|
75
|
+
```python
|
|
76
|
+
import ssl
|
|
77
|
+
from python_socks.sync import Proxy
|
|
78
|
+
|
|
79
|
+
proxy = Proxy.from_url('socks5://user:password@127.0.0.1:1080')
|
|
80
|
+
|
|
81
|
+
# `connect` returns standard Python socket in blocking mode
|
|
82
|
+
sock = proxy.connect(dest_host='check-host.net', dest_port=443)
|
|
83
|
+
|
|
84
|
+
sock = ssl.create_default_context().wrap_socket(
|
|
85
|
+
sock=sock,
|
|
86
|
+
server_hostname='check-host.net'
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
request = (
|
|
90
|
+
b'GET /ip HTTP/1.1\r\n'
|
|
91
|
+
b'Host: check-host.net\r\n'
|
|
92
|
+
b'Connection: close\r\n\r\n'
|
|
93
|
+
)
|
|
94
|
+
sock.sendall(request)
|
|
95
|
+
response = sock.recv(4096)
|
|
96
|
+
print(response)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### Async (asyncio)
|
|
100
|
+
```python
|
|
101
|
+
import ssl
|
|
102
|
+
import asyncio
|
|
103
|
+
from python_socks.async_.asyncio import Proxy
|
|
104
|
+
|
|
105
|
+
proxy = Proxy.from_url('socks5://user:password@127.0.0.1:1080')
|
|
106
|
+
|
|
107
|
+
# `connect` returns standard Python socket in non-blocking mode
|
|
108
|
+
# so we can pass it to asyncio.open_connection(...)
|
|
109
|
+
sock = await proxy.connect(dest_host='check-host.net', dest_port=443)
|
|
110
|
+
|
|
111
|
+
reader, writer = await asyncio.open_connection(
|
|
112
|
+
host=None,
|
|
113
|
+
port=None,
|
|
114
|
+
sock=sock,
|
|
115
|
+
ssl=ssl.create_default_context(),
|
|
116
|
+
server_hostname='check-host.net',
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
request = (
|
|
120
|
+
b'GET /ip HTTP/1.1\r\n'
|
|
121
|
+
b'Host: check-host.net\r\n'
|
|
122
|
+
b'Connection: close\r\n\r\n'
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
writer.write(request)
|
|
126
|
+
response = await reader.read(-1)
|
|
127
|
+
print(response)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
#### Async (trio)
|
|
131
|
+
```python
|
|
132
|
+
import ssl
|
|
133
|
+
import trio
|
|
134
|
+
from python_socks.async_.trio import Proxy
|
|
135
|
+
|
|
136
|
+
proxy = Proxy.from_url('socks5://user:password@127.0.0.1:1080')
|
|
137
|
+
|
|
138
|
+
# `connect` returns trio socket
|
|
139
|
+
# so we can pass it to trio.SocketStream
|
|
140
|
+
sock = await proxy.connect(dest_host='check-host.net', dest_port=443)
|
|
141
|
+
|
|
142
|
+
stream = trio.SocketStream(sock)
|
|
143
|
+
|
|
144
|
+
stream = trio.SSLStream(
|
|
145
|
+
stream, ssl.create_default_context(),
|
|
146
|
+
server_hostname='check-host.net'
|
|
147
|
+
)
|
|
148
|
+
await stream.do_handshake()
|
|
149
|
+
|
|
150
|
+
request = (
|
|
151
|
+
b'GET /ip HTTP/1.1\r\n'
|
|
152
|
+
b'Host: check-host.net\r\n'
|
|
153
|
+
b'Connection: close\r\n\r\n'
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
await stream.send_all(request)
|
|
157
|
+
response = await stream.receive_some(4096)
|
|
158
|
+
print(response)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### Async (curio)
|
|
162
|
+
```python
|
|
163
|
+
import curio.ssl as curiossl
|
|
164
|
+
from python_socks.async_.curio import Proxy
|
|
165
|
+
|
|
166
|
+
proxy = Proxy.from_url('socks5://user:password@127.0.0.1:1080')
|
|
167
|
+
# `connect` returns curio.io.Socket
|
|
168
|
+
sock = await proxy.connect(
|
|
169
|
+
dest_host='check-host.net',
|
|
170
|
+
dest_port=443
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
request = (
|
|
174
|
+
b'GET /ip HTTP/1.1\r\n'
|
|
175
|
+
b'Host: check-host.net\r\n'
|
|
176
|
+
b'Connection: close\r\n\r\n'
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
ssl_context = curiossl.create_default_context()
|
|
180
|
+
sock = await ssl_context.wrap_socket(
|
|
181
|
+
sock, do_handshake_on_connect=False, server_hostname='check-host.net'
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
await sock.do_handshake()
|
|
185
|
+
|
|
186
|
+
stream = sock.as_stream()
|
|
187
|
+
|
|
188
|
+
await stream.write(request)
|
|
189
|
+
response = await stream.read(1024)
|
|
190
|
+
print(response)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
#### Async (anyio)
|
|
194
|
+
```python
|
|
195
|
+
import ssl
|
|
196
|
+
from python_socks.async_.anyio import Proxy
|
|
197
|
+
|
|
198
|
+
proxy = Proxy.from_url('socks5://user:password@127.0.0.1:1080')
|
|
199
|
+
|
|
200
|
+
# `connect` returns AnyioSocketStream
|
|
201
|
+
stream = await proxy.connect(
|
|
202
|
+
dest_host='check-host.net',
|
|
203
|
+
dest_port=443,
|
|
204
|
+
dest_ssl=ssl.create_default_context(),
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
request = (
|
|
208
|
+
b'GET /ip HTTP/1.1\r\n'
|
|
209
|
+
b'Host: check-host.net\r\n'
|
|
210
|
+
b'Connection: close\r\n\r\n'
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
await stream.write_all(request)
|
|
214
|
+
response = await stream.read()
|
|
215
|
+
print(response)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## More complex example
|
|
219
|
+
|
|
220
|
+
#### A urllib3 PoolManager that routes connections via the proxy
|
|
221
|
+
|
|
222
|
+
```python
|
|
223
|
+
from urllib3 import PoolManager, HTTPConnectionPool, HTTPSConnectionPool
|
|
224
|
+
from urllib3.connection import HTTPConnection, HTTPSConnection
|
|
225
|
+
from python_socks.sync import Proxy
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
class ProxyHTTPConnection(HTTPConnection):
|
|
229
|
+
def __init__(self, *args, **kwargs):
|
|
230
|
+
socks_options = kwargs.pop('_socks_options')
|
|
231
|
+
self._proxy_url = socks_options['proxy_url']
|
|
232
|
+
super().__init__(*args, **kwargs)
|
|
233
|
+
|
|
234
|
+
def _new_conn(self):
|
|
235
|
+
proxy = Proxy.from_url(self._proxy_url)
|
|
236
|
+
return proxy.connect(
|
|
237
|
+
dest_host=self.host,
|
|
238
|
+
dest_port=self.port,
|
|
239
|
+
timeout=self.timeout
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
class ProxyHTTPSConnection(ProxyHTTPConnection, HTTPSConnection):
|
|
244
|
+
pass
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
class ProxyHTTPConnectionPool(HTTPConnectionPool):
|
|
248
|
+
ConnectionCls = ProxyHTTPConnection
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
class ProxyHTTPSConnectionPool(HTTPSConnectionPool):
|
|
252
|
+
ConnectionCls = ProxyHTTPSConnection
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
class ProxyPoolManager(PoolManager):
|
|
256
|
+
def __init__(self, proxy_url, timeout=5, num_pools=10, headers=None,
|
|
257
|
+
**connection_pool_kw):
|
|
258
|
+
|
|
259
|
+
connection_pool_kw['_socks_options'] = {'proxy_url': proxy_url}
|
|
260
|
+
connection_pool_kw['timeout'] = timeout
|
|
261
|
+
|
|
262
|
+
super().__init__(num_pools, headers, **connection_pool_kw)
|
|
263
|
+
|
|
264
|
+
self.pool_classes_by_scheme = {
|
|
265
|
+
'http': ProxyHTTPConnectionPool,
|
|
266
|
+
'https': ProxyHTTPSConnectionPool,
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
### and how to use it
|
|
271
|
+
manager = ProxyPoolManager('socks5://user:password@127.0.0.1:1080')
|
|
272
|
+
response = manager.request('GET', 'https://check-host.net/ip')
|
|
273
|
+
print(response.data)
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
|
|
@@ -4,7 +4,7 @@ python_socks/_basic_auth.py,sha256=dnPOtNi6lMer0O0TRrsfZK1XA4oATrMftuWK9x8pMio,2
|
|
|
4
4
|
python_socks/_errors.py,sha256=l2j03Zna_EJhNqF3yApTYuQ147BcY0k74pkT4HAlRp4,245
|
|
5
5
|
python_socks/_helpers.py,sha256=WTqOACKhJ80bCLWqeoXHPKp6YWCg66vLtai5AM7HJNY,2517
|
|
6
6
|
python_socks/_types.py,sha256=dgQifNf2mIwdKoX7YmI91H_lUsW9-Y0ZkZGlIV6_NNw,90
|
|
7
|
-
python_socks/_version.py,sha256=
|
|
7
|
+
python_socks/_version.py,sha256=ysF0_DwtAVl6cSBXA-tZ7JUWoNPo03_rmz-qVSq_D7M,49
|
|
8
8
|
python_socks/_connectors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
python_socks/_connectors/abc.py,sha256=1fgjPiv64UAMiJDsJXYr-GofPGhuHTwTzaodQfrzf7Q,397
|
|
10
10
|
python_socks/_connectors/factory_async.py,sha256=y9JGVk-ub9FMuQlIp2s5y95F7JMvA2fEdWGRKLUpRXc,997
|
|
@@ -19,7 +19,7 @@ python_socks/_protocols/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG
|
|
|
19
19
|
python_socks/_protocols/errors.py,sha256=4XqU4AqgrWaedmUVGMjd6TvQKXv3mV0H76s5lf8aazY,150
|
|
20
20
|
python_socks/_protocols/http.py,sha256=C6lCkGzpbNWHQWi6ftXHhS85VPw9-Jik_igcXkzTbng,2406
|
|
21
21
|
python_socks/_protocols/socks4.py,sha256=QlWtGaPIa0jUfHreHIXZalHM9q4GQ684h7JSvxFwiJI,3023
|
|
22
|
-
python_socks/_protocols/socks5.py,sha256=
|
|
22
|
+
python_socks/_protocols/socks5.py,sha256=2W-x_6UAjjfH_7g90Ke6-pQFnJjBN-PDBFxRoWdoo7A,9408
|
|
23
23
|
python_socks/async_/__init__.py,sha256=TeBn5oirLy6aPoWcTc3OW9OxXh5Uv5LADwF_Y7f7HjY,64
|
|
24
24
|
python_socks/async_/_proxy_chain.py,sha256=A2LbxoRBgdHSikVJcrOAVDx79DT5Isq3RM_DiHTI8dM,824
|
|
25
25
|
python_socks/async_/anyio/__init__.py,sha256=pZnrND4Qd-pIGg7KI1ML41kZNkWHmkd3vrvwZZIJyk4,106
|
|
@@ -70,8 +70,8 @@ python_socks/sync/v2/_connect.py,sha256=eqMKsH2wVnGZhV24_t9QfsNhjbnKtnipj7wzSNct
|
|
|
70
70
|
python_socks/sync/v2/_proxy.py,sha256=B2phFTScHW7SZxnn2Vspc9fHof6GVJhW9BGuJ6S7Sa8,3396
|
|
71
71
|
python_socks/sync/v2/_ssl_transport.py,sha256=MURwzvKu-S2-MI7o8KaZTvvBFOiiKIu5R0ERVIMvERE,6088
|
|
72
72
|
python_socks/sync/v2/_stream.py,sha256=Jq89x1xmIX3L_v-WyS1nRTItjTnYTcDcfDblsANxfJI,1544
|
|
73
|
-
python_socks-2.4.
|
|
74
|
-
python_socks-2.4.
|
|
75
|
-
python_socks-2.4.
|
|
76
|
-
python_socks-2.4.
|
|
77
|
-
python_socks-2.4.
|
|
73
|
+
python_socks-2.4.2.dist-info/LICENSE.txt,sha256=tAkwu8-AdEyGxGoSvJ2gVmQdcicWw3j1ZZueVV74M-E,11357
|
|
74
|
+
python_socks-2.4.2.dist-info/METADATA,sha256=QNpy0n8oY--GCJ5uwziT1L8uKJHmYsORibIKyvHzEs8,7057
|
|
75
|
+
python_socks-2.4.2.dist-info/WHEEL,sha256=OqRkF0eY5GHssMorFjlbTIq072vpHpF60fIQA6lS9xA,92
|
|
76
|
+
python_socks-2.4.2.dist-info/top_level.txt,sha256=7qyDAVwjTZ0sIYG1iatFbE-SLpWhONjaoMQ0Ib2DX0Q,13
|
|
77
|
+
python_socks-2.4.2.dist-info/RECORD,,
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: python-socks
|
|
3
|
-
Version: 2.4.0
|
|
4
|
-
Summary: Core proxy (SOCKS4, SOCKS5, HTTP tunneling) functionality for Python
|
|
5
|
-
Home-page: https://github.com/romis2012/python-socks
|
|
6
|
-
Author: Roman Snegirev
|
|
7
|
-
Author-email: snegiryev@gmail.com
|
|
8
|
-
License: Apache 2
|
|
9
|
-
Keywords: socks socks5 socks4 http proxy asyncio trio curio anyio
|
|
10
|
-
Platform: UNKNOWN
|
|
11
|
-
Description-Content-Type: text/markdown
|
|
12
|
-
License-File: LICENSE.txt
|
|
13
|
-
Provides-Extra: anyio
|
|
14
|
-
Requires-Dist: anyio (<4.0.0,>=3.3.4) ; extra == 'anyio'
|
|
15
|
-
Provides-Extra: asyncio
|
|
16
|
-
Requires-Dist: async-timeout (>=3.0.1) ; extra == 'asyncio'
|
|
17
|
-
Provides-Extra: curio
|
|
18
|
-
Requires-Dist: curio (>=1.4) ; extra == 'curio'
|
|
19
|
-
Provides-Extra: trio
|
|
20
|
-
Requires-Dist: trio (>=0.16.0) ; extra == 'trio'
|
|
21
|
-
|
|
22
|
-
2.4.0
|
|
23
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|