-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathproxy_usage.py
More file actions
267 lines (201 loc) · 7.88 KB
/
proxy_usage.py
File metadata and controls
267 lines (201 loc) · 7.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
"""
Proxy Usage Example for CycleTLS Python
This example demonstrates how to configure and use different types of proxies
with CycleTLS, including HTTP, HTTPS, SOCKS4, SOCKS5, and authenticated proxies.
Proxy URL Format:
- HTTP: http://hostname:port
- HTTPS: https://hostname:port
- SOCKS4: socks4://hostname:port
- SOCKS5: socks5://hostname:port
- With auth: protocol://username:password@hostname:port
"""
from cycletls import CycleTLS
def example_http_proxy():
"""Example: Using an HTTP proxy"""
print("\n=== HTTP Proxy Example ===")
try:
with CycleTLS() as client:
# Configure HTTP proxy
proxy_url = "http://127.0.0.1:8080"
response = client.get(
"https://httpbin.org/ip",
proxy=proxy_url,
timeout=10
)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.text}")
except Exception as e:
print(f"Error with HTTP proxy: {e}")
print("Note: Make sure an HTTP proxy is running on 127.0.0.1:8080")
def example_https_proxy():
"""Example: Using an HTTPS proxy"""
print("\n=== HTTPS Proxy Example ===")
try:
with CycleTLS() as client:
# Configure HTTPS proxy
proxy_url = "https://127.0.0.1:8443"
response = client.get(
"https://httpbin.org/ip",
proxy=proxy_url,
timeout=10
)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.text}")
except Exception as e:
print(f"Error with HTTPS proxy: {e}")
print("Note: Make sure an HTTPS proxy is running on 127.0.0.1:8443")
def example_socks4_proxy():
"""Example: Using a SOCKS4 proxy"""
print("\n=== SOCKS4 Proxy Example ===")
try:
with CycleTLS() as client:
# Configure SOCKS4 proxy
proxy_url = "socks4://127.0.0.1:9050"
response = client.get(
"https://httpbin.org/ip",
proxy=proxy_url,
timeout=10
)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.text}")
except Exception as e:
print(f"Error with SOCKS4 proxy: {e}")
print("Note: Make sure a SOCKS4 proxy is running on 127.0.0.1:9050")
def example_socks5_proxy():
"""Example: Using a SOCKS5 proxy"""
print("\n=== SOCKS5 Proxy Example ===")
try:
with CycleTLS() as client:
# Configure SOCKS5 proxy (e.g., Tor)
proxy_url = "socks5://127.0.0.1:9050"
response = client.get(
"https://httpbin.org/ip",
proxy=proxy_url,
timeout=10
)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.text}")
except Exception as e:
print(f"Error with SOCKS5 proxy: {e}")
print("Note: Make sure a SOCKS5 proxy is running on 127.0.0.1:9050")
print("Tip: You can use Tor Browser or install Tor service")
def example_socks5h_proxy():
"""Example: Using a SOCKS5h proxy (hostname resolution via proxy)"""
print("\n=== SOCKS5h Proxy Example ===")
try:
with CycleTLS() as client:
# SOCKS5h resolves DNS queries through the proxy
# This provides better privacy as DNS queries don't leak
proxy_url = "socks5h://127.0.0.1:9050"
response = client.get(
"https://httpbin.org/ip",
proxy=proxy_url,
timeout=10
)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.text}")
except Exception as e:
print(f"Error with SOCKS5h proxy: {e}")
def example_authenticated_proxy():
"""Example: Using a proxy with username and password authentication"""
print("\n=== Authenticated Proxy Example ===")
try:
with CycleTLS() as client:
# Proxy with authentication
# Format: protocol://username:password@hostname:port
proxy_url = "http://myuser:mypassword@127.0.0.1:8080"
response = client.get(
"https://httpbin.org/ip",
proxy=proxy_url,
timeout=10
)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.text}")
except Exception as e:
print(f"Error with authenticated proxy: {e}")
print("Note: Update username and password with valid credentials")
def example_proxy_with_ja3():
"""Example: Using proxy with JA3 fingerprint customization"""
print("\n=== Proxy with JA3 Fingerprint Example ===")
try:
with CycleTLS() as client:
# Combine proxy with JA3 fingerprinting
proxy_url = "socks5://127.0.0.1:9050"
# Chrome-like JA3 fingerprint
ja3_chrome = "771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,0-23-65281-10-11-35-16-5-13-18-51-45-43-27-21,29-23-24,0"
response = client.get(
"https://ja3er.com/json",
proxy=proxy_url,
ja3=ja3_chrome,
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
timeout=10
)
print(f"Status Code: {response.status_code}")
if response.ok:
data = response.json()
print(f"JA3 Hash: {data.get('ja3_hash', 'N/A')}")
print(f"User Agent: {data.get('User-Agent', 'N/A')}")
except Exception as e:
print(f"Error with proxy and JA3: {e}")
def example_proxy_post_request():
"""Example: Using proxy with POST request"""
print("\n=== Proxy with POST Request Example ===")
try:
with CycleTLS() as client:
proxy_url = "socks5://127.0.0.1:9050"
payload = {
"name": "CycleTLS",
"type": "HTTP client",
"features": ["TLS fingerprinting", "Proxy support"]
}
response = client.post(
"https://httpbin.org/post",
proxy=proxy_url,
json_data=payload,
timeout=10
)
print(f"Status Code: {response.status_code}")
if response.ok:
data = response.json()
print(f"Echo'd JSON: {data.get('json', {})}")
except Exception as e:
print(f"Error with proxy POST request: {e}")
def example_no_proxy():
"""Example: Making request without proxy (baseline)"""
print("\n=== No Proxy (Direct Connection) Example ===")
try:
with CycleTLS() as client:
# Direct connection without proxy
response = client.get(
"https://httpbin.org/ip",
timeout=10
)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.text}")
except Exception as e:
print(f"Error: {e}")
def main():
"""Run all proxy examples"""
print("=" * 60)
print("CycleTLS Proxy Configuration Examples")
print("=" * 60)
# Run examples
example_no_proxy()
example_http_proxy()
example_https_proxy()
example_socks4_proxy()
example_socks5_proxy()
example_socks5h_proxy()
example_authenticated_proxy()
example_proxy_with_ja3()
example_proxy_post_request()
print("\n" + "=" * 60)
print("Examples completed!")
print("\nNotes:")
print("- Most examples require a local proxy server to be running")
print("- For SOCKS5 examples, you can use Tor (default port 9050)")
print("- For HTTP/HTTPS examples, you can use tools like mitmproxy or squid")
print("- Update proxy URLs and credentials as needed for your setup")
print("=" * 60)
if __name__ == "__main__":
main()