-
Notifications
You must be signed in to change notification settings - Fork 6
/
no_delete_proxy.py
121 lines (109 loc) · 5.42 KB
/
no_delete_proxy.py
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
# -*- coding: utf-8 -*-
# @Author :Solana0x
# @File :main.py
# @Software :PyCharm
# here in this code the proxy is not deleted from the file automatically !!
import asyncio
import random
import ssl
import json
import time
import uuid
from loguru import logger
from websockets_proxy import Proxy, proxy_connect
async def connect_to_wss(socks5_proxy, user_id):
device_id = str(uuid.uuid3(uuid.NAMESPACE_DNS, socks5_proxy))
logger.info(device_id)
while True:
try:
await asyncio.sleep(random.uniform(0.1, 1.0)) # Reduced frequency
custom_headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"
}
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
uri = "wss://proxy2.wynd.network:4444/" #
server_hostname = "proxy.wynd.network"
proxy = Proxy.from_url(socks5_proxy)
async with proxy_connect(uri, proxy=proxy, ssl=ssl_context, extra_headers={
"Origin": "chrome-extension://lkbnfiajjmbhnfledhphioinpickokdi",
"User-Agent": custom_headers["User-Agent"]
}) as websocket:
async def send_ping():
while True:
send_message = json.dumps(
{"id": str(uuid.uuid4()), "version": "1.0.0", "action": "PING", "data": {}})
logger.debug(send_message)
await websocket.send(send_message)
await asyncio.sleep(110) # Increased interval to reduce bandwidth usage
send_ping_task = asyncio.create_task(send_ping())
try:
while True:
response = await websocket.recv()
message = json.loads(response)
logger.info(message)
if message.get("action") == "AUTH":
auth_response = {
"id": message["id"],
"origin_action": "AUTH",
"result": {
"browser_id": device_id,
"user_id": user_id,
"user_agent": custom_headers['User-Agent'],
"timestamp": int(time.time()),
"device_type": "extension",
"version": "4.26.2",
"extension_id": "lkbnfiajjmbhnfledhphioinpickokdi"
}
}
logger.debug(auth_response)
await websocket.send(json.dumps(auth_response))
elif message.get("action") == "PONG":
pong_response = {"id": message["id"], "origin_action": "PONG"}
logger.debug(pong_response)
await websocket.send(json.dumps(pong_response))
finally:
send_ping_task.cancel()
except Exception as e:
logger.error(f"Error with proxy {socks5_proxy}: {str(e)}")
if any(error_msg in str(e) for error_msg in ["Device creation limit exceeded"]):
logger.info(f"Removing error proxy from the list: {socks5_proxy}")
remove_proxy_from_list(socks5_proxy)
return None # Signal to the main loop to replace this proxy
else:
continue # Continue to try to reconnect or handle other errors
async def main():
_user_id = 'Replace Your User ID HERE' # Replace Your User ID HERE
proxy_file = 'proxy.txt' # your Path to Proxy3.txt file
# formate => socks5://username:pass@ip:port
with open(proxy_file, 'r') as file:
all_proxies = file.read().splitlines()
active_proxies = random.sample(all_proxies, 100) # Number of proxies to use
tasks = {asyncio.create_task(connect_to_wss(proxy, _user_id)): proxy for proxy in active_proxies}
while True:
done, pending = await asyncio.wait(tasks.keys(), return_when=asyncio.FIRST_COMPLETED)
for task in done:
if task.result() is None:
failed_proxy = tasks[task]
logger.info(f"Removing and replacing failed proxy: {failed_proxy}")
active_proxies.remove(failed_proxy)
new_proxy = random.choice(all_proxies)
active_proxies.append(new_proxy)
new_task = asyncio.create_task(connect_to_wss(new_proxy, _user_id))
tasks[new_task] = new_proxy # Replace the task in the dictionary
tasks.pop(task) # Remove the completed task whether it succeeded or failed
# Replenish the tasks if any have completed
for proxy in set(active_proxies) - set(tasks.values()):
new_task = asyncio.create_task(connect_to_wss(proxy, _user_id))
tasks[new_task] = proxy
def remove_proxy_from_list(proxy):
with open("proxy.txt", "r+") as file:
lines = file.readlines()
file.seek(0)
for line in lines:
if line.strip() != proxy:
file.write(line)
file.truncate()
if __name__ == '__main__':
asyncio.run(main())