linksocks 3.0.12__cp311-cp311-win_amd64.whl → 3.0.13__cp311-cp311-win_amd64.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.

Potentially problematic release.


This version of linksocks might be problematic. Click here for more details.

linksocks/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  """linksocks: SOCKS5 over WebSocket proxy library."""
2
2
 
3
- __version__ = "3.0.12"
3
+ __version__ = "3.0.13"
4
4
 
5
5
  from ._server import Server
6
6
  from ._client import Client
@@ -0,0 +1,479 @@
1
+ Metadata-Version: 2.1
2
+ Name: linksocks
3
+ Version: 3.0.13
4
+ Summary: Python bindings for LinkSocks - SOCKS proxy over WebSocket
5
+ Home-page: https://github.com/linksocks/linksocks
6
+ Author: jackzzs
7
+ Author-email: jackzzs@outlook.com
8
+ License: MIT
9
+ Project-URL: Bug Reports, https://github.com/linksocks/linksocks/issues
10
+ Project-URL: Source, https://github.com/linksocks/linksocks
11
+ Project-URL: Documentation, https://github.com/linksocks/linksocks#readme
12
+ Project-URL: Changelog, https://github.com/linksocks/linksocks/releases
13
+ Keywords: socks proxy websocket network tunneling firewall bypass load-balancing go bindings
14
+ Platform: any
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Intended Audience :: System Administrators
18
+ Classifier: Operating System :: POSIX :: Linux
19
+ Classifier: Operating System :: MacOS
20
+ Classifier: Operating System :: Microsoft :: Windows
21
+ Classifier: Programming Language :: Python :: 3
22
+ Classifier: Programming Language :: Python :: 3.9
23
+ Classifier: Programming Language :: Python :: 3.10
24
+ Classifier: Programming Language :: Python :: 3.11
25
+ Classifier: Programming Language :: Python :: 3.12
26
+ Classifier: Programming Language :: Python :: 3.13
27
+ Classifier: Programming Language :: Go
28
+ Classifier: Topic :: Internet :: Proxy Servers
29
+ Classifier: Topic :: Internet :: WWW/HTTP
30
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
31
+ Classifier: Topic :: System :: Networking
32
+ Requires-Python: >=3.9
33
+ Description-Content-Type: text/markdown
34
+ Requires-Dist: setuptools >=40.0
35
+ Requires-Dist: click >=8.0
36
+ Requires-Dist: loguru
37
+ Requires-Dist: rich
38
+ Provides-Extra: dev
39
+ Requires-Dist: pytest >=6.0 ; extra == 'dev'
40
+ Requires-Dist: pytest-cov >=2.10 ; extra == 'dev'
41
+ Requires-Dist: pytest-mock >=3.0 ; extra == 'dev'
42
+ Requires-Dist: pytest-xdist ; extra == 'dev'
43
+ Requires-Dist: black >=21.0 ; extra == 'dev'
44
+ Requires-Dist: flake8 >=3.8 ; extra == 'dev'
45
+ Requires-Dist: mypy >=0.800 ; extra == 'dev'
46
+ Requires-Dist: httpx[socks] ; extra == 'dev'
47
+ Requires-Dist: requests ; extra == 'dev'
48
+ Requires-Dist: pysocks ; extra == 'dev'
49
+
50
+ # LinkSocks Python Bindings
51
+
52
+ [![PyPI version](https://badge.fury.io/py/linksocks.svg)](https://badge.fury.io/py/linksocks)
53
+ [![Python versions](https://img.shields.io/pypi/pyversions/linksocks.svg)](https://pypi.org/project/linksocks/)
54
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
55
+
56
+ Python bindings for LinkSocks - a SOCKS5 over WebSocket proxy tool.
57
+
58
+ ## Overview
59
+
60
+ LinkSocks is a SOCKS proxy implementation over WebSocket protocol that allows you to securely expose SOCKS proxy services under Web Application Firewall (WAF) protection. This package provides Python bindings for the Go implementation.
61
+
62
+ ### Key Features
63
+
64
+ - 🔄 **Forward & Reverse Proxy**: Support both forward and reverse SOCKS5 proxy modes
65
+ - 🌐 **WebSocket Transport**: Works under WAF protection using standard WebSocket connections
66
+ - ⚖️ **Load Balancing**: Round-robin load balancing for reverse proxy with multiple clients
67
+ - 🔐 **Authentication**: SOCKS5 proxy authentication and secure token-based WebSocket authentication
68
+ - 🌍 **Protocol Support**: Full IPv6 over SOCKS5 and UDP over SOCKS5 support
69
+ - 🐍 **Pythonic API**: Both synchronous and asynchronous APIs with context manager support
70
+
71
+ ## Installation
72
+
73
+ ### Using pip (Recommended)
74
+
75
+ ```bash
76
+ pip install linksocks
77
+ ```
78
+
79
+ ### Development Installation
80
+
81
+ ```bash
82
+ git clone https://github.com/linksocks/linksocks.git
83
+ cd linksocks/_bindings/python
84
+ pip install -e .
85
+ ```
86
+
87
+ ### Requirements
88
+
89
+ - Python 3.8 or later
90
+ - Go 1.19 or later (for building from source)
91
+
92
+ ## Quick Start
93
+
94
+ ### Forward Proxy Example
95
+
96
+ ```python
97
+ import asyncio
98
+ from linksocks import Server, Client
99
+
100
+ async def main():
101
+ # Create server and client with async context managers
102
+ async with Server(ws_port=8765) as server:
103
+ # Add forward token asynchronously
104
+ token = await server.async_add_forward_token()
105
+
106
+ async with Client(token, ws_url="ws://localhost:8765", socks_port=9870, no_env_proxy=True) as client:
107
+ print("✅ Forward proxy ready!")
108
+ print("🌐 SOCKS5 proxy: 127.0.0.1:9870")
109
+ print("🔧 Test: curl --socks5 127.0.0.1:9870 http://httpbin.org/ip")
110
+
111
+ # Keep running
112
+ await asyncio.sleep(3600)
113
+
114
+ if __name__ == "__main__":
115
+ asyncio.run(main())
116
+ ```
117
+
118
+ ### Reverse Proxy Example
119
+
120
+ ```python
121
+ import asyncio
122
+ from linksocks import Server, Client
123
+
124
+ async def main():
125
+ # Create server and client with async context managers
126
+ async with Server(ws_port=8765) as server:
127
+ # Add reverse token (port is auto-allocated)
128
+ result = server.add_reverse_token()
129
+ print(f"🔑 Reverse token: {result.token}")
130
+ print(f"🌐 SOCKS5 proxy will be available on: 127.0.0.1:{result.port}")
131
+
132
+ # Create client in reverse mode
133
+ async with Client(result.token, ws_url="ws://localhost:8765", reverse=True, no_env_proxy=True) as client:
134
+ print("✅ Reverse proxy ready!")
135
+ print(f"🔧 Test: curl --socks5 127.0.0.1:{result.port} http://httpbin.org/ip")
136
+
137
+ # Keep running
138
+ await asyncio.sleep(3600)
139
+
140
+ if __name__ == "__main__":
141
+ asyncio.run(main())
142
+ ```
143
+
144
+ ## API Reference
145
+
146
+ ### Server Class
147
+
148
+ The `Server` class manages WebSocket connections and provides SOCKS5 proxy functionality.
149
+
150
+ ```python
151
+ from linksocks import Server
152
+
153
+ # Create server with options
154
+ server = Server(
155
+ ws_host="0.0.0.0", # WebSocket listen address
156
+ ws_port=8765, # WebSocket listen port
157
+ socks_host="127.0.0.1", # SOCKS5 listen address (reverse mode)
158
+ buffer_size=32768, # Buffer size for data transfer
159
+ api_key="your_api_key", # Enable HTTP API
160
+ channel_timeout=30.0, # WebSocket channel timeout (seconds)
161
+ connect_timeout=10.0, # Connection timeout (seconds)
162
+ fast_open=False, # Enable fast open optimization
163
+ upstream_proxy="socks5://proxy:1080", # Upstream proxy
164
+ upstream_username="user", # Upstream proxy username
165
+ upstream_password="pass" # Upstream proxy password
166
+ )
167
+ ```
168
+
169
+ #### Token Management
170
+
171
+ ```python
172
+ # Add forward proxy token (synchronous)
173
+ token = server.add_forward_token("custom_token") # or auto-generate with None
174
+
175
+ # Add forward proxy token (asynchronous - recommended)
176
+ token = await server.async_add_forward_token("custom_token")
177
+
178
+ # Add reverse proxy token
179
+ result = server.add_reverse_token(
180
+ token="custom_token", # optional, auto-generated if None
181
+ port=9870, # optional, auto-allocated if None
182
+ username="socks_user", # optional, SOCKS5 auth username
183
+ password="socks_pass", # optional, SOCKS5 auth password
184
+ allow_manage_connector=True # optional, allow client connector management
185
+ )
186
+ print(f"Token: {result.token}, Port: {result.port}")
187
+
188
+ # Add connector token
189
+ connector_token = server.add_connector_token("connector_token", "reverse_token")
190
+
191
+ # Remove any token
192
+ success = server.remove_token("token_to_remove")
193
+ ```
194
+
195
+ #### Running the Server
196
+
197
+ ```python
198
+ # Asynchronous (recommended) - automatically waits for ready
199
+ async with server:
200
+ print("Server is ready!") # No need for async_wait_ready()
201
+ # Server runs while in context
202
+
203
+ # Synchronous - requires manual wait
204
+ server.wait_ready() # Blocks until ready
205
+ # Server runs in background
206
+ server.close() # Clean shutdown
207
+
208
+ # Manual wait with timeout (only needed for synchronous usage)
209
+ server.wait_ready(timeout=30.0) # 30 second timeout
210
+ await server.async_wait_ready(timeout="30s") # Go duration string (rarely needed)
211
+ ```
212
+
213
+ ### Client Class
214
+
215
+ The `Client` class connects to WebSocket servers and provides SOCKS5 functionality.
216
+
217
+ ```python
218
+ from linksocks import Client
219
+
220
+ # Create client with options
221
+ client = Client(
222
+ token="your_token", # Authentication token (required)
223
+ ws_url="ws://localhost:8765", # WebSocket server URL
224
+ reverse=False, # Enable reverse proxy mode
225
+ socks_host="127.0.0.1", # SOCKS5 listen address (forward mode)
226
+ socks_port=9870, # SOCKS5 listen port (forward mode)
227
+ socks_username="user", # SOCKS5 auth username
228
+ socks_password="pass", # SOCKS5 auth password
229
+ socks_wait_server=True, # Wait for server before starting SOCKS5
230
+ reconnect=True, # Auto-reconnect on disconnect
231
+ reconnect_delay=5.0, # Reconnect delay (seconds)
232
+ buffer_size=32768, # Buffer size for data transfer
233
+ channel_timeout=30.0, # WebSocket channel timeout
234
+ connect_timeout=10.0, # Connection timeout
235
+ threads=4, # Number of processing threads
236
+ fast_open=False, # Enable fast open optimization
237
+ upstream_proxy="socks5://proxy:1080", # Upstream proxy
238
+ upstream_username="proxy_user", # Upstream proxy username
239
+ upstream_password="proxy_pass", # Upstream proxy password
240
+ no_env_proxy=False # Ignore proxy environment variables
241
+ )
242
+ ```
243
+
244
+ #### Running the Client
245
+
246
+ ```python
247
+ # Asynchronous (recommended) - automatically waits for ready
248
+ async with client:
249
+ print(f"Client ready! SOCKS5 port: {client.socks_port}")
250
+ print(f"Connected: {client.is_connected}")
251
+ # Client runs while in context
252
+
253
+ # Synchronous - requires manual wait
254
+ client.wait_ready()
255
+ print(f"Connected: {client.is_connected}")
256
+ client.close() # Clean shutdown
257
+ ```
258
+
259
+ #### Connector Management (Reverse Mode)
260
+
261
+ ```python
262
+ # Add connector token (reverse mode only)
263
+ connector_token = client.add_connector("my_connector") # or auto-generate
264
+ connector_token = await client.async_add_connector(None) # async version
265
+ ```
266
+
267
+ ### Logging
268
+
269
+ ```python
270
+ import logging
271
+ from linksocks import set_log_level
272
+
273
+ # Set global log level
274
+ set_log_level(logging.DEBUG)
275
+ set_log_level("INFO") # String format
276
+
277
+ # Use custom logger
278
+ logger = logging.getLogger("my_app")
279
+ logger.setLevel(logging.DEBUG)
280
+ handler = logging.StreamHandler()
281
+ handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))
282
+ logger.addHandler(handler)
283
+
284
+ server = Server(logger=logger)
285
+ client = Client("token", logger=logger)
286
+ ```
287
+
288
+ ## Advanced Examples
289
+
290
+ ### Agent Proxy with Connector Management
291
+
292
+ ```python
293
+ import asyncio
294
+ from linksocks import Server, Client
295
+
296
+ async def agent_proxy():
297
+ # Server with connector autonomy enabled
298
+ async with Server(ws_port=8765) as server:
299
+ result = server.add_reverse_token(allow_manage_connector=True)
300
+ print(f"🔑 Provider token: {result.token}")
301
+ print(f"🌐 SOCKS5 proxy will be available on: 127.0.0.1:{result.port}")
302
+
303
+ # Provider client (provides network access)
304
+ async with Client(result.token, ws_url="ws://localhost:8765", reverse=True, no_env_proxy=True) as provider:
305
+ print("✅ Agent proxy server and provider ready!")
306
+
307
+ # Provider can manage its own connectors
308
+ connector_token = await provider.async_add_connector("my_connector")
309
+ print(f"🔑 Connector token: {connector_token}")
310
+
311
+ # Now external connectors can use this token
312
+ print(f"🔧 Start connector: linksocks connector -t {connector_token} -u ws://localhost:8765 -p 1180")
313
+
314
+ await asyncio.sleep(3600)
315
+
316
+ asyncio.run(agent_proxy())
317
+ ```
318
+
319
+ ### Error Handling and Monitoring
320
+
321
+ ```python
322
+ import asyncio
323
+ import logging
324
+ from linksocks import Client
325
+
326
+ async def robust_client():
327
+ logger = logging.getLogger("robust_client")
328
+
329
+ client = Client(
330
+ "your_token",
331
+ ws_url="ws://server:8765",
332
+ reconnect=True,
333
+ reconnect_delay=5.0,
334
+ no_env_proxy=True,
335
+ logger=logger
336
+ )
337
+
338
+ try:
339
+ async with client:
340
+ logger.info("✅ Client connected successfully")
341
+
342
+ # Monitor connection status
343
+ while True:
344
+ if not client.is_connected:
345
+ logger.warning("⚠️ Connection lost, reconnecting...")
346
+
347
+ await asyncio.sleep(5)
348
+
349
+ except asyncio.TimeoutError:
350
+ logger.error("❌ Connection timeout after 30 seconds")
351
+ except Exception as e:
352
+ logger.error(f"❌ Client error: {e}")
353
+ finally:
354
+ logger.info("🔄 Client shutting down")
355
+
356
+ asyncio.run(robust_client())
357
+ ```
358
+
359
+ ### HTTP API Integration
360
+
361
+ ```python
362
+ import asyncio
363
+ import aiohttp
364
+ from linksocks import Server
365
+
366
+ async def api_server_example():
367
+ # Start server with API enabled
368
+ server = Server(ws_port=8765, api_key="secret_api_key")
369
+
370
+ async with server:
371
+ print("✅ Server with API ready!")
372
+
373
+ # Use HTTP API to manage tokens
374
+ async with aiohttp.ClientSession() as session:
375
+ headers = {"X-API-Key": "secret_api_key"}
376
+
377
+ # Add forward token via API
378
+ async with session.post(
379
+ "http://localhost:8765/api/token",
380
+ headers=headers,
381
+ json={"type": "forward", "token": "api_token"}
382
+ ) as resp:
383
+ result = await resp.json()
384
+ print(f"📝 Added token via API: {result}")
385
+
386
+ # Get server status
387
+ async with session.get(
388
+ "http://localhost:8765/api/status",
389
+ headers=headers
390
+ ) as resp:
391
+ status = await resp.json()
392
+ print(f"📊 Server status: {status}")
393
+
394
+ await asyncio.sleep(3600)
395
+
396
+ asyncio.run(api_server_example())
397
+ ```
398
+
399
+ ## Type Hints
400
+
401
+ The package includes comprehensive type hints for better IDE support:
402
+
403
+ ```python
404
+ from typing import Optional
405
+ from linksocks import Server, Client, ReverseTokenResult
406
+
407
+ def create_proxy_pair(token: str, port: Optional[int] = None) -> tuple[Server, Client]:
408
+ server = Server(ws_port=8765)
409
+ server.add_forward_token(token)
410
+
411
+ client = Client(token, ws_url="ws://localhost:8765", socks_port=port or 9870, no_env_proxy=True)
412
+ return server, client
413
+
414
+ # ReverseTokenResult is a dataclass
415
+ server = Server(ws_port=8765)
416
+ result: ReverseTokenResult = server.add_reverse_token()
417
+ print(f"Token: {result.token}, Port: {result.port}")
418
+ ```
419
+
420
+ ## Comparison with CLI Tool
421
+
422
+ | Feature | Python Bindings | Go CLI Tool |
423
+ |---------|-----------------|-------------|
424
+ | **Integration** | Library for Python apps | Standalone binary |
425
+ | **API Style** | Object-oriented, async/sync | Command-line flags |
426
+ | **Use Cases** | Embedded in applications | Quick setup, scripting |
427
+ | **Performance** | Same (uses Go backend) | Same |
428
+ | **Features** | Full feature parity | Full feature parity |
429
+
430
+ ## Troubleshooting
431
+
432
+ ### Common Issues
433
+
434
+ 1. **Import Error**: Make sure Go 1.19+ is installed when building from source
435
+ 2. **Connection Refused**: Check that server is running and ports are correct
436
+ 3. **Authentication Failed**: Verify tokens match between server and client
437
+ 4. **Port Already in Use**: Choose different ports or check for existing processes
438
+
439
+ ### Debug Logging
440
+
441
+ ```python
442
+ import logging
443
+ from linksocks import set_log_level
444
+
445
+ # Enable debug logging
446
+ set_log_level(logging.DEBUG)
447
+
448
+ # Or use environment variable
449
+ import os
450
+ os.environ["LINKSOCKS_LOG_LEVEL"] = "DEBUG"
451
+ ```
452
+
453
+ ### Performance Tuning
454
+
455
+ ```python
456
+ # Increase buffer size for high-throughput scenarios
457
+ server = Server(buffer_size=65536)
458
+ client = Client("token", buffer_size=65536, threads=8)
459
+
460
+ # Enable fast open for lower latency
461
+ server = Server(fast_open=True)
462
+ client = Client("token", fast_open=True)
463
+ ```
464
+
465
+ ## Contributing
466
+
467
+ We welcome contributions! Please see the main [LinkSocks repository](https://github.com/linksocks/linksocks) for contribution guidelines.
468
+
469
+ ## License
470
+
471
+ This project is licensed under the MIT License.
472
+
473
+ ## Links
474
+
475
+ - 📚 [Full Documentation](https://linksocks.github.io/linksocks/)
476
+ - 🐛 [Issue Tracker](https://github.com/linksocks/linksocks/issues)
477
+ - 💬 [Discussions](https://github.com/linksocks/linksocks/discussions)
478
+ - 📦 [PyPI Package](https://pypi.org/project/linksocks/)
479
+ - 🐳 [Docker Hub](https://hub.docker.com/r/jackzzs/linksocks)
@@ -0,0 +1,21 @@
1
+ linksocks/__init__.py,sha256=4nPtnyJJ8MaKA9QifSD8CS3jGOQYPEX_DLUBlaeaEPI,266
2
+ linksocks/_base.py,sha256=kTGSvsOYEkHbMT9L2VwnEYw60hamgp6Ml1gTy2sXJZA,7609
3
+ linksocks/_cli.py,sha256=Of8TyugpMFlYdeD6oMtpH3B2CpC38H0tv05YwUT9qQ0,11581
4
+ linksocks/_client.py,sha256=HvYpE4XFiFiI1ifeiR1Sh2yUfBBRoTDksS-r7NrdbPg,11356
5
+ linksocks/_logging_config.py,sha256=mRJi6tX-m-_ehKZUdUFRD6jVZmtwwZpvaUyvA3yK1kI,7029
6
+ linksocks/_server.py,sha256=2Gmghb9d5JzyP1xhKCFx25tQkZSnw4JmdGShtNUo9U8,13482
7
+ linksocks/_utils.py,sha256=zkwGIEuhWiVXj5PTvZuQV-786jkxdzPmPYK9JNvHSJM,5350
8
+ linksockslib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ linksockslib/_linksockslib.cp311-win_amd64.h,sha256=KTCcxYUgOGVRRzDwJ5KmhWKRYe6_lolESqfVUR3xxjk,78787
10
+ linksockslib/_linksockslib.cp311-win_amd64.pyd,sha256=T_giafXwDsiaQ2-bQA-9YcUxJDRikg3J3sDSQzM22u8,25510140
11
+ linksockslib/build.py,sha256=2XZawDNHzeboh7YSLyYXGkF90TjBpjMzz4IxjU5Hc9I,81586
12
+ linksockslib/go.py,sha256=mU2xaKcYY2EIFKo4O0dbgQzGmxo69Xh5TyARZ3dkzzQ,128800
13
+ linksockslib/linksocks.py,sha256=Jp_6tGaKCt4phPsAGmujUCIqlKcg_vTeeg2i-6kAH1E,209692
14
+ linksockslib/linksockslib.c,sha256=eMAETGiuhWyk_qInITvKojcNUss_qdHviSysXl6MQJE,642637
15
+ linksockslib/linksockslib.go,sha256=6g7mKkzuRjZeI6YO4qmwyTgNgvU7HHhhlDgF7KRCLU4,286834
16
+ linksockslib/linksockslib_go.h,sha256=KTCcxYUgOGVRRzDwJ5KmhWKRYe6_lolESqfVUR3xxjk,78787
17
+ linksocks-3.0.13.dist-info/METADATA,sha256=5OFnmQ6tSqPgJ-NVcBQCsGghrQ-fnLM3SA5b6PpIICg,16583
18
+ linksocks-3.0.13.dist-info/WHEEL,sha256=ircjsfhzblqgSzO8ow7-0pXK-RVqDqNRGQ8F650AUNM,102
19
+ linksocks-3.0.13.dist-info/entry_points.txt,sha256=N584rBdQV-KY-sNHyxyspBe9b1SzYQfZ3_ad8rKEP3k,49
20
+ linksocks-3.0.13.dist-info/top_level.txt,sha256=YNkAF_AIyMZ5J93liBuasWxns38CKzcKbx3bfUyoXiU,23
21
+ linksocks-3.0.13.dist-info/RECORD,,