-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmain.py
More file actions
157 lines (141 loc) · 7.5 KB
/
main.py
File metadata and controls
157 lines (141 loc) · 7.5 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
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/130.0.0.0 Safari/537.36"
}
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
# Define server hostname and both ports
server_hostname = "proxy2.wynd.network"
ports = [4444, 4650]
for port in ports:
uri = f"wss://{server_hostname}:{port}/"
try:
proxy = Proxy.from_url(socks5_proxy)
# Connecting with the 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:
logger.info(f"Connected to {uri} via proxy {socks5_proxy}")
# Function to send PING message periodically
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(10) # Increased interval to reduce bandwidth usage
# Start sending ping messages
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()
break # Exit the loop if connected successfully
except Exception as e:
logger.error(f"Error connecting to {uri} with proxy {socks5_proxy}: {str(e)}")
# If the first URI fails, try the next one
continue
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 [
"[SSL: WRONG_VERSION_NUMBER]",
"invalid length of packed IP address string",
"Empty connect reply",
"Device creation limit exceeded",
"sent 1011 (internal error) keepalive ping timeout; no close frame received"]):
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():
# Prompt the user to input their user ID
_user_id = input('Please enter your user ID: ').strip()
if not _user_id:
logger.error("User ID is required. Exiting.")
return # Exit if no user ID is provided
# Prompt the user to input the number of proxies they want to use
try:
num_proxies_to_use = int(input('Please enter the number of proxies you want to use: ').strip())
if num_proxies_to_use <= 0:
raise ValueError("The number of proxies must be a positive integer.")
except ValueError as e:
logger.error(f"Invalid number of proxies: {e}. Exiting.")
return # Exit if an invalid number is entered
proxy_file = 'proxy.txt' # Path to your proxy.txt file
# format => socks5://username:pass@ip:port
try:
with open(proxy_file, 'r') as file:
all_proxies = file.read().splitlines()
except FileNotFoundError:
logger.error(f"Proxy file '{proxy_file}' not found. Exiting.")
return # Exit if the proxy file is not found
# Check if there are enough proxies available
num_proxies_to_use = min(num_proxies_to_use, len(all_proxies)) # Ensure we don't exceed the available proxies
logger.info(f"Using {num_proxies_to_use} proxies.")
active_proxies = random.sample(all_proxies, num_proxies_to_use) # Select the 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())